bit::Trie< Array >::Iterator Class Reference

A class for traversing in a trie. More...

#include <Trie.hh>

List of all members.

Public Member Functions

Creating iterators
 Iterator ()
 Construct an un-attached iterator.
 Iterator (const Trie< Array > &trie)
 Construct an iterator attached to an trie.
 Iterator (const Iterator &it, unsigned int length)
 Construct a prefix iterator containing only a few first symbols.
Iterator information
unsigned int length () const
 The length of the iterator inside the trie.
u32 symbol_index (unsigned int level) const
 The iterator position at the symbol vector.
u32 symbol_index () const
 The iterator position at the symbol vector on highest level.
u32 child_limit_index (unsigned int level) const
 The iterator position at the child_limit vector.
u32 child_limit_index () const
 The iterator position at the child_limit vector on highest level.
u32 symbol (unsigned int level) const
 Return the symbol from the current iterator position.
u32 symbol () const
 Return the symbol from the current iterator position at the highest level.
std::vector< u32symbol_vec () const
 Return the symbol vector corresponding to the iterator.
u32 child_limit (unsigned int level) const
 Return the index of the first child after the children of the iterator node at the given level.
u32 child_limit () const
 Return the index of the first child after the children of the current node.
u32 first_child (unsigned int level) const
 Return the index of the first child of the iterator node at the given level.
u32 first_child () const
 Return the index of the first child of the current node.
u32 first_sibling (unsigned int level) const
 Return the index of the first sibling on the current node at a given level.
u32 first_sibling () const
 Return the index of the first sibling on the current node.
u32 sibling_limit (unsigned int level) const
 Return the index after siblings after the siblings of the current node at a given level.
u32 sibling_limit () const
 Return the index after siblings after the siblings of the current node.
bool is_root () const
 Is the iterator at the virtual root node?
bool is_separated_leaf () const
 Is the node leaf node in a separated level.
u32 num_children (unsigned int level) const
 The number of children the current iterator has at a given level.
u32 num_children () const
 The number of children the current node has.
Moving the iterator
Iterator parent () const
 Iterator positioned at the parent node.
void goto_root ()
 Move the iterator to the virtual root node.
bool goto_parent ()
 Move iterator to the parent of the current node.
bool goto_first_child ()
 Move the iterator to the first child of the current node.
bool goto_next_sibling ()
 Move the iterator to the next sibling.
bool goto_child (u32 symbol)
 Move the iterator to child having the specified symbol.
bool goto_next_depth_first ()
 Move the iterator to the next node in depth-first order.
bool goto_leaf ()
 Move the iterator deeper along the first children until a leaf is reached.
bool goto_next_depth_first_post ()
 Move the iterator to the next node in depth-first post-order, i.e., processing children before parents.
bool goto_next_on_level (unsigned int level)
 Move the iterator depth first to the next node on a given level.
void goto_backoff_full ()
 Move the iterator to the first backoff node found in the model.
bool goto_backoff_once ()
 Move the iterator to the backoff node.
Comparing iterators
bool operator== (const Iterator it)
 Test if two iterators point to the same position.
bool operator!= (const Iterator it)
 Test if two iterators do not point to the same position.

Private Attributes

const Trie< Array > * m_trie
 The trie that the iterator is attached to.
std::vector< u32m_symbol_stack
 The path of symbol vector indices that define the position of the iterator.
std::vector< u32m_child_limit_stack
 The path of child_limit vector indices that define the position of the iterator.

Friends

class Trie


Detailed Description

template<class Array>
class bit::Trie< Array >::Iterator

A class for traversing in a trie.


Constructor & Destructor Documentation

template<class Array>
bit::Trie< Array >::Iterator::Iterator  )  [inline]
 

Construct an un-attached iterator.

template<class Array>
bit::Trie< Array >::Iterator::Iterator const Trie< Array > &  trie  )  [inline]
 

Construct an iterator attached to an trie.

The iterator will be located at the root of the trie.

Parameters:
trie = trie to which the iterator is attached

template<class Array>
bit::Trie< Array >::Iterator::Iterator const Iterator it,
unsigned int  length
[inline]
 

Construct a prefix iterator containing only a few first symbols.

Parameters:
it = iterator to copy
length = the number of symbols copied


Member Function Documentation

template<class Array>
u32 bit::Trie< Array >::Iterator::child_limit  )  const [inline]
 

Return the index of the first child after the children of the current node.

Zero MAY be returned if there are no children.

template<class Array>
u32 bit::Trie< Array >::Iterator::child_limit unsigned int  level  )  const [inline]
 

Return the index of the first child after the children of the iterator node at the given level.

Parameters:
level = the level from which the child_limit is fetched
Exceptions:
bit::out_of_range if level is greater than length() - 1
bit::invalid_call if leaf-node in separated array

template<class Array>
u32 bit::Trie< Array >::Iterator::child_limit_index  )  const [inline]
 

The iterator position at the child_limit vector on highest level.

Returns:
max_u32 if leaf-node in separated array
Exceptions:
bit::out_of_range if the iterator is positioned at the virtual root node

template<class Array>
u32 bit::Trie< Array >::Iterator::child_limit_index unsigned int  level  )  const [inline]
 

The iterator position at the child_limit vector.

Parameters:
level = the level from which the position is fetched
Returns:
max_u32 if leaf-node in separated array
Exceptions:
bit::out_of_range if level is greater than length() - 1

template<class Array>
u32 bit::Trie< Array >::Iterator::first_child  )  const [inline]
 

Return the index of the first child of the current node.

It is safe to call this for the first node of the level; zero is returned.

template<class Array>
u32 bit::Trie< Array >::Iterator::first_child unsigned int  level  )  const [inline]
 

Return the index of the first child of the iterator node at the given level.

It is safe to call this for the first node of the level; zero is returned.

Parameters:
level = the level from which the index is fetched.
Exceptions:
bit::out_of_range if level is greater than length() - 1
bit::invalid_call if leaf-node in separated array

template<class Array>
u32 bit::Trie< Array >::Iterator::first_sibling  )  const [inline]
 

Return the index of the first sibling on the current node.

Exceptions:
bit::out_of_range if called for root

template<class Array>
u32 bit::Trie< Array >::Iterator::first_sibling unsigned int  level  )  const [inline]
 

Return the index of the first sibling on the current node at a given level.

Exceptions:
bit::out_of_range if level exceeds length() - 1

template<class Array>
void bit::Trie< Array >::Iterator::goto_backoff_full  )  [inline]
 

Move the iterator to the first backoff node found in the model.

Backoffing removes symbols from the beginning of the string until the resulting string is found in the model.

Exceptions:
bit::invalid_call if called at root

template<class Array>
bool bit::Trie< Array >::Iterator::goto_backoff_once  )  [inline]
 

Move the iterator to the backoff node.

Backoffing removes a symbol from the beginning of the string. If backoff node does not exist, the iterator is left at the original position.

Returns:
false if the backoff node does not exist in the model
Exceptions:
bit::invalid_call if called at root

template<class Array>
bool bit::Trie< Array >::Iterator::goto_child u32  symbol  )  [inline]
 

Move the iterator to child having the specified symbol.

Parameters:
symbol = symbol to find
Returns:
false if child with symbol not found

template<class Array>
bool bit::Trie< Array >::Iterator::goto_first_child  )  [inline]
 

Move the iterator to the first child of the current node.

Returns:
false if no children

template<class Array>
bool bit::Trie< Array >::Iterator::goto_leaf  )  [inline]
 

Move the iterator deeper along the first children until a leaf is reached.

Returns:
false if the iterator was not moved at all

template<class Array>
bool bit::Trie< Array >::Iterator::goto_next_depth_first  )  [inline]
 

Move the iterator to the next node in depth-first order.

Returns:
false if no more nodes

template<class Array>
bool bit::Trie< Array >::Iterator::goto_next_depth_first_post  )  [inline]
 

Move the iterator to the next node in depth-first post-order, i.e., processing children before parents.

Assumes that iterator is positioned at root to begin the search.

Returns:
false if no more nodes (and the iterator will be at root)

template<class Array>
bool bit::Trie< Array >::Iterator::goto_next_on_level unsigned int  level  )  [inline]
 

Move the iterator depth first to the next node on a given level.

Parameters:
level = level to iterate (0 = unigram)
Returns:
false if no next node (the iterator is left at the original position)

template<class Array>
bool bit::Trie< Array >::Iterator::goto_next_sibling  )  [inline]
 

Move the iterator to the next sibling.

Returns:
false if no more siblings for the current parent
Exceptions:
bit::out_of_range if called for root

template<class Array>
bool bit::Trie< Array >::Iterator::goto_parent  )  [inline]
 

Move iterator to the parent of the current node.

Returns:
false if no parent

template<class Array>
void bit::Trie< Array >::Iterator::goto_root  )  [inline]
 

Move the iterator to the virtual root node.

template<class Array>
bool bit::Trie< Array >::Iterator::is_root  )  const [inline]
 

Is the iterator at the virtual root node?

template<class Array>
bool bit::Trie< Array >::Iterator::is_separated_leaf  )  const [inline]
 

Is the node leaf node in a separated level.

template<class Array>
unsigned int bit::Trie< Array >::Iterator::length  )  const [inline]
 

The length of the iterator inside the trie.

The length is zero, when the iterator is positioned at the abstract root node.

template<class Array>
u32 bit::Trie< Array >::Iterator::num_children  )  const [inline]
 

The number of children the current node has.

template<class Array>
u32 bit::Trie< Array >::Iterator::num_children unsigned int  level  )  const [inline]
 

The number of children the current iterator has at a given level.

template<class Array>
bool bit::Trie< Array >::Iterator::operator!= const Iterator  it  )  [inline]
 

Test if two iterators do not point to the same position.

template<class Array>
bool bit::Trie< Array >::Iterator::operator== const Iterator  it  )  [inline]
 

Test if two iterators point to the same position.

template<class Array>
Iterator bit::Trie< Array >::Iterator::parent  )  const [inline]
 

Iterator positioned at the parent node.

Exceptions:
bit::invalid_call if could not move to parent node

template<class Array>
u32 bit::Trie< Array >::Iterator::sibling_limit  )  const [inline]
 

Return the index after siblings after the siblings of the current node.

Exceptions:
bit::out_of_range if called for root

template<class Array>
u32 bit::Trie< Array >::Iterator::sibling_limit unsigned int  level  )  const [inline]
 

Return the index after siblings after the siblings of the current node at a given level.

Exceptions:
bit::out_of_range if level exceeds length() - 1

template<class Array>
u32 bit::Trie< Array >::Iterator::symbol  )  const [inline]
 

Return the symbol from the current iterator position at the highest level.

Exceptions:
bit::out_of_range if called at virtual root node.

template<class Array>
u32 bit::Trie< Array >::Iterator::symbol unsigned int  level  )  const [inline]
 

Return the symbol from the current iterator position.

Parameters:
level = the level from which the symbol is fetched
Exceptions:
bit::out_of_range if level is greater than length() - 1

template<class Array>
u32 bit::Trie< Array >::Iterator::symbol_index  )  const [inline]
 

The iterator position at the symbol vector on highest level.

Exceptions:
bit::out_of_range if the iterator is positioned at the virtual root node

template<class Array>
u32 bit::Trie< Array >::Iterator::symbol_index unsigned int  level  )  const [inline]
 

The iterator position at the symbol vector.

Parameters:
level = the level from which the position is fetched
Exceptions:
bit::out_of_range if level is greater than length() - 1

template<class Array>
std::vector<u32> bit::Trie< Array >::Iterator::symbol_vec  )  const [inline]
 

Return the symbol vector corresponding to the iterator.


Friends And Related Function Documentation

template<class Array>
friend class Trie [friend]
 


Member Data Documentation

template<class Array>
std::vector<u32> bit::Trie< Array >::Iterator::m_child_limit_stack [private]
 

The path of child_limit vector indices that define the position of the iterator.

If the last element is max_u32, the current node does not have children.

template<class Array>
std::vector<u32> bit::Trie< Array >::Iterator::m_symbol_stack [private]
 

The path of symbol vector indices that define the position of the iterator.

template<class Array>
const Trie<Array>* bit::Trie< Array >::Iterator::m_trie [private]
 

The trie that the iterator is attached to.


The documentation for this class was generated from the following file:
Generated on Mon Jan 8 15:51:04 2007 for bit by  doxygen 1.4.6