#include <tree-node.h>
Inheritance diagram for TreeNode:
A TreeNode has an identifier of type LargeIndex (a vector of ints). TreeNode 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 TreeNode 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 TreeNodes 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 TreeNode, you should have your copy constructor call the base class's copy constructor:
MyNode::MyNode(const MyNode& other) : TreeNode(other) {
// your copy code
}
Public Member Functions | |
TreeNode () | |
Create a new node with an empty index. | |
TreeNode (const LargeIndex &index) | |
Create a new node with the given index. | |
TreeNode (const TreeNode &other) | |
A 'copy' constructor, which only copies over the index. | |
virtual | ~TreeNode () |
const LargeIndex & | GetIndex () const |
TreeNode * | GetParent () |
TreeNode * | GetPreviousSibling () |
TreeNode * | GetNextSibling () |
TreeNode * | GetFirstChild () |
TreeNode * | GetLastChild () |
void | SetParent (TreeNode *parent) |
void | SetPreviousSibling (TreeNode *sibling) |
void | SetNextSibling (TreeNode *sibling) |
void | SetFirstChild (TreeNode *child) |
void | SetLastChild (TreeNode *child) |
void | SetIndex (const LargeIndex &index) |
bool | HasParent () const |
bool | HasPreviousSibling () const |
bool | HasNextSibling () const |
bool | HasChild () 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 TreeNode &other)=0 |
Add the data from <other> to self. | |
bool | operator< (const TreeNode &other) const |
Returns true if this node's index is smaller than that of <other>. | |
Static Public Member Functions | |
static bool | CompareNodes (const TreeNode *one, const TreeNode *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. |
TreeNode | ( | ) |
Create a new node with an empty index.
TreeNode | ( | const LargeIndex & | index | ) |
Create a new node with the given index.
A 'copy' constructor, which only copies over the index.
The pointers to data will NOT be copied over; they will be NULL.
~TreeNode | ( | ) | [virtual] |
const LargeIndex & GetIndex | ( | ) | const |
TreeNode * GetParent | ( | ) |
TreeNode * GetPreviousSibling | ( | ) |
TreeNode * GetNextSibling | ( | ) |
TreeNode * GetFirstChild | ( | ) |
TreeNode * GetLastChild | ( | ) |
void SetParent | ( | TreeNode * | parent | ) |
void SetPreviousSibling | ( | TreeNode * | sibling | ) |
void SetNextSibling | ( | TreeNode * | sibling | ) |
void SetFirstChild | ( | TreeNode * | child | ) |
void SetLastChild | ( | TreeNode * | child | ) |
void SetIndex | ( | const LargeIndex & | index | ) |
bool HasParent | ( | ) | const |
bool HasPreviousSibling | ( | ) | const |
bool HasNextSibling | ( | ) | const |
bool HasChild | ( | ) | const |
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 TreeNode & | other | ) | [pure virtual] |
bool operator< | ( | const TreeNode & | other | ) | const |
Returns true if this node's index is smaller than that of <other>.
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] |