#include <lab4_vit.H>
Public Member Functions | |
WordTree () | |
Ctor; initializes object to just contain root node. | |
void | clear () |
Clears object except for root node. | |
unsigned | size () const |
Returns number of nodes in tree. | |
unsigned | get_root_node () const |
Returns index of root node. | |
unsigned | insert_node (unsigned parentIdx, unsigned lastWord) |
Given an existing node parentIdx , returns index of child node reached when traversing arc labeled with word index lastWord . | |
unsigned | get_parent_node (unsigned nodeIdx) const |
Returns index of parent node for node with index nodeIdx . | |
unsigned | get_last_word (unsigned nodeIdx) const |
Returns index of word labeling arc from node nodeIdx to its parent node. |
This object can be used to hold a list of word sequences in the form of a tree. Each node in the tree is assigned an integer index, and each arc in the tree is labeled with an integer index corresponding to a word label. Each node in the tree can be viewed as representing the word sequence labeling the path from the root to that node.
To get the index of the root node, use get_root_node(). To find/create the node reached by extending a node with a word, use insert_node(). To recover the word sequence a node corresponds to, you can use get_parent_node() and get_last_word().
WordTree::WordTree | ( | ) | [inline] |
Ctor; initializes object to just contain root node.
void WordTree::clear | ( | ) | [inline] |
Clears object except for root node.
unsigned WordTree::size | ( | ) | const [inline] |
Returns number of nodes in tree.
unsigned WordTree::get_root_node | ( | ) | const [inline] |
Returns index of root node.
unsigned WordTree::insert_node | ( | unsigned | parentIdx, | |
unsigned | lastWord | |||
) | [inline] |
Given an existing node parentIdx
, returns index of child node reached when traversing arc labeled with word index lastWord
.
If node doesn't exist, it is created.
unsigned WordTree::get_parent_node | ( | unsigned | nodeIdx | ) | const [inline] |
Returns index of parent node for node with index nodeIdx
.