TreeNode Class Reference

#include <tree-node.h>

Inheritance diagram for TreeNode:

Bin List of all members.

Detailed Description

An indexed node, used by Tree.

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 LargeIndexGetIndex () const
TreeNodeGetParent ()
TreeNodeGetPreviousSibling ()
TreeNodeGetNextSibling ()
TreeNodeGetFirstChild ()
TreeNodeGetLastChild ()
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.


Constructor & Destructor Documentation

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.

The pointers to data will NOT be copied over; they will be NULL.

~TreeNode (  )  [virtual]


Member Function Documentation

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:

It will then call ReadData().
See also:
ReadData()

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().

See also:
WriteData().

virtual void Combine ( const TreeNode other  )  [pure virtual]

Add the data from <other> to self.

Implemented in Bin.

bool operator< ( const TreeNode other  )  const

Returns true if this node's index is smaller than that of <other>.

bool CompareNodes ( const TreeNode one,
const TreeNode two 
) [static]

Returns true if <one>'s index is smaller than that of <two>.

virtual void ReadData ( istream &  input_stream  )  [protected, pure virtual]

Read the data, excluding the index, from a stream.

Implemented in Bin.

virtual void WriteData ( ostream &  output_stream  )  const [protected, pure virtual]

Write the data, excluding the index, to a stream.

Implemented in Bin.


The documentation for this class was generated from the following files:
Generated on Wed May 2 11:17:13 2007 for libpmk by  doxygen 1.5.1