#include <sparse-tree-node.h>
Inheritance diagram for SparseTreeNode:
A SparseTreeNode has an identifier of type LargeIndex (a vector of ints). SparseTreeNode also contains pointers to parents, children, and siblings, but makes no effort to maintain about them, and as such, we make no guarantees on it. For example, the "sibling" pointer can point to an arbitrary bin which may or may not be the real sibling. Tree handles the getting/setting of these pointers.
To augment a SparseTreeNode with your own data, there are three functions you need to provide: (1) reading the data from a stream, (2) writing the data to a stream, and (3) how to combine two nodes. The definition of "combine" will vary depending on what you're doing, but the general idea is that sometimes you will have two SparseTreeNodes with the same LargeIndex that you want to insert into a tree. It is advisable that you make the output of Combine() is symmetric, since there are no guarantees on what Tree does with duplicate-index bins other than calling Combine().
Remember that if you implement a copy constructor for your SparseTreeNode, you should have your copy constructor call the base class's copy constructor:
MyNode::MyNode(const MyNode& other) : SparseTreeNode(other) {
// your copy code
}
Public Member Functions | |
SparseTreeNode () | |
Create a new node with an empty index. | |
SparseTreeNode (const LargeIndex &index) | |
Create a new node with the given index. | |
SparseTreeNode (const SparseTreeNode &other) | |
A 'copy' constructor, which only copies over the index. | |
virtual | ~SparseTreeNode () |
const LargeIndex & | index () const |
SparseTreeNode * | parent () |
SparseTreeNode * | prev_sibling () |
SparseTreeNode * | next_sibling () |
SparseTreeNode * | first_child () |
SparseTreeNode * | last_child () |
void | set_parent (SparseTreeNode *parent) |
void | set_prev_sibling (SparseTreeNode *sibling) |
void | set_next_sibling (SparseTreeNode *sibling) |
void | set_first_child (SparseTreeNode *child) |
void | set_last_child (SparseTreeNode *child) |
void | set_index (const LargeIndex &index) |
bool | has_parent () const |
bool | has_prev_sibling () const |
bool | has_next_sibling () const |
bool | has_child () const |
void | ReadFromStream (istream &input_stream) |
Read the data, including the index, from a stream. | |
void | WriteToStream (ostream &output_stream) const |
Write the data, including the index, to a stream. | |
virtual void | Combine (const SparseTreeNode &other)=0 |
Add the data from <other> to self. | |
bool | operator< (const SparseTreeNode &other) const |
Returns true if this node's index is smaller than that of <other>. | |
Static Public Member Functions | |
static bool | CompareNodes (const SparseTreeNode *one, const SparseTreeNode *two) |
Returns true if <one>'s index is smaller than that of <two>. | |
Protected Member Functions | |
virtual void | ReadData (istream &input_stream)=0 |
Read the data, excluding the index, from a stream. | |
virtual void | WriteData (ostream &output_stream) const=0 |
Write the data, excluding the index, to a stream. |
SparseTreeNode | ( | ) |
Create a new node with an empty index.
SparseTreeNode | ( | const LargeIndex & | index | ) |
Create a new node with the given index.
SparseTreeNode | ( | const SparseTreeNode & | other | ) |
A 'copy' constructor, which only copies over the index.
The pointers to data will NOT be copied over; they will be NULL.
~SparseTreeNode | ( | ) | [virtual] |
const LargeIndex& index | ( | ) | const [inline] |
SparseTreeNode* parent | ( | ) | [inline] |
SparseTreeNode* prev_sibling | ( | ) | [inline] |
SparseTreeNode* next_sibling | ( | ) | [inline] |
SparseTreeNode* first_child | ( | ) | [inline] |
SparseTreeNode* last_child | ( | ) | [inline] |
void set_parent | ( | SparseTreeNode * | parent | ) | [inline] |
void set_prev_sibling | ( | SparseTreeNode * | sibling | ) | [inline] |
void set_next_sibling | ( | SparseTreeNode * | sibling | ) | [inline] |
void set_first_child | ( | SparseTreeNode * | child | ) | [inline] |
void set_last_child | ( | SparseTreeNode * | child | ) | [inline] |
void set_index | ( | const LargeIndex & | index | ) | [inline] |
bool has_parent | ( | ) | const [inline] |
bool has_prev_sibling | ( | ) | const [inline] |
bool has_next_sibling | ( | ) | const [inline] |
bool has_child | ( | ) | const [inline] |
void ReadFromStream | ( | istream & | input_stream | ) |
Read the data, including the index, from a stream.
Calling this will override the node's current index. The format is:
void WriteToStream | ( | ostream & | output_stream | ) | const |
Write the data, including the index, to a stream.
This will simply write the index to the stream, followed by WriteData().
virtual void Combine | ( | const SparseTreeNode & | other | ) | [pure virtual] |
bool operator< | ( | const SparseTreeNode & | other | ) | const |
Returns true if this node's index is smaller than that of <other>.
bool CompareNodes | ( | const SparseTreeNode * | one, | |
const SparseTreeNode * | two | |||
) | [static] |
Returns true if <one>'s index is smaller than that of <two>.
virtual void ReadData | ( | istream & | input_stream | ) | [protected, pure virtual] |
virtual void WriteData | ( | ostream & | output_stream | ) | const [protected, pure virtual] |