vg
tools for working with variation graphs
Public Member Functions | Public Attributes | Private Attributes | List of all members
vg::ZipCodeTree::seed_iterator Class Reference

#include <zip_code_tree.hpp>

Public Member Functions

 seed_iterator (size_t start_index, const ZipCodeTree &ziptree)
 
 seed_iterator (const seed_iterator &other)=default
 
 seed_iterator (seed_iterator &&other)=default
 
seed_iteratoroperator= (const seed_iterator &other)=default
 
seed_iteratoroperator= (seed_iterator &&other)=default
 
seed_iteratoroperator++ ()
 
bool operator== (const seed_iterator &other) const
 
bool operator!= (const seed_iterator &other) const
 Compare for inequality. More...
 
tree_item_t current_item () const
 What item does index point to? More...
 
vector< oriented_seed_toperator* () const
 
size_t get_index () const
 
bool get_right_to_left () const
 
stack< size_t > get_chain_numbers () const
 

Public Attributes

const vector< tree_item_t > & zip_code_tree
 A reference to the ziptree vector. More...
 

Private Attributes

stack< size_t > chain_numbers
 Within each parent snarl, which chain are we in? More...
 
size_t index
 Where we are in the stored tree. More...
 
size_t cyclic_snarl_nestedness
 How far inside of a cyclic snarl are we? More...
 
bool right_to_left
 
vector< oriented_seed_tcurrent_seeds
 Seeds at this position. More...
 

Detailed Description

Iterator that visits seeds left to right in the tree's in-order traversal

Iteration flow

Each seed is visited in from left to right, in the same order as get_all_seeds() would return them.

The first time any given seed is visited, right_to_left is true, indicating that a distance iterator should be set off going in the default direction of right to left.

Once the right-to-left step has been done, then the iterator decides whether to do a second, left-to-right step, with right_to_left set to false. This will happen if inside a cyclic snarl, even if not necessarily the direct parent. Calling ++() will toggle right_to_left instead of moving the internal iteration index. The next call to ++() would then reset right_to_left back to true, and finally advance the iterator rightward to the next seed.

For seeds not inside cyclic snarls, ++() will simply move rightward.

We need to traverse seeds in cyclic snarls in both directions because the chains are not necessarily traversed in a single direction, and are stored in an arbitrary orientation.

How to use this iterator

The intent of this iterator is to hide a lot of the fiddly bits required to iterate over a zip tree with cyclic and non-cyclic snarls. All a caller needs to do is

Seeds from both iterators will be automatically oriented based on the direction of traversal. That is, you can Just Trust Me (TM) for all seed orientations which iterators yield.

Constructor & Destructor Documentation

◆ seed_iterator() [1/3]

vg::ZipCodeTree::seed_iterator::seed_iterator ( size_t  start_index,
const ZipCodeTree ziptree 
)

Make an iterator starting from start_index until the end of the given ziptree

◆ seed_iterator() [2/3]

vg::ZipCodeTree::seed_iterator::seed_iterator ( const seed_iterator other)
default

◆ seed_iterator() [3/3]

vg::ZipCodeTree::seed_iterator::seed_iterator ( seed_iterator &&  other)
default

Member Function Documentation

◆ current_item()

tree_item_t vg::ZipCodeTree::seed_iterator::current_item ( ) const
inline

What item does index point to?

◆ get_chain_numbers()

stack<size_t> vg::ZipCodeTree::seed_iterator::get_chain_numbers ( ) const
inline

◆ get_index()

size_t vg::ZipCodeTree::seed_iterator::get_index ( ) const
inline

◆ get_right_to_left()

bool vg::ZipCodeTree::seed_iterator::get_right_to_left ( ) const
inline

◆ operator!=()

bool vg::ZipCodeTree::seed_iterator::operator!= ( const seed_iterator other) const
inline

Compare for inequality.

◆ operator*()

vector<oriented_seed_t> vg::ZipCodeTree::seed_iterator::operator* ( ) const
inline

Get the index and orientation of the seed we are currently at. Also return all other seeds on the same position

◆ operator++()

auto vg::ZipCodeTree::seed_iterator::operator++ ( )

Advance right until we hit another seed or the end Automatically handle updating chain_numbers and cyclic_snarl_nestedness

◆ operator=() [1/2]

seed_iterator& vg::ZipCodeTree::seed_iterator::operator= ( const seed_iterator other)
default

◆ operator=() [2/2]

seed_iterator& vg::ZipCodeTree::seed_iterator::operator= ( seed_iterator &&  other)
default

◆ operator==()

bool vg::ZipCodeTree::seed_iterator::operator== ( const seed_iterator other) const
inline

Compare for equality to see if we hit end This just trusts that the two iterators are for the same tree

Member Data Documentation

◆ chain_numbers

stack<size_t> vg::ZipCodeTree::seed_iterator::chain_numbers
private

Within each parent snarl, which chain are we in?

◆ current_seeds

vector<oriented_seed_t> vg::ZipCodeTree::seed_iterator::current_seeds
private

Seeds at this position.

◆ cyclic_snarl_nestedness

size_t vg::ZipCodeTree::seed_iterator::cyclic_snarl_nestedness
private

How far inside of a cyclic snarl are we?

◆ index

size_t vg::ZipCodeTree::seed_iterator::index
private

Where we are in the stored tree.

◆ right_to_left

bool vg::ZipCodeTree::seed_iterator::right_to_left
private

Direction a distance iterator should be set off NOT the direction this iterator moves; a seed_iterator always moves left to right

◆ zip_code_tree

const vector<tree_item_t>& vg::ZipCodeTree::seed_iterator::zip_code_tree

A reference to the ziptree vector.


The documentation for this class was generated from the following files: