Intrusive Containers
Classes

Intrusive Binary Tree (unbalenced). More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  TreeInNode< R, N, K, n >
 
class  TreeInRoot< R, N, K, n >
 
class  TreeInRoot< R, N, K, n >
 
class  TreeInNode< R, N, K, n >
 

Detailed Description

Intrusive Binary Tree (unbalenced).

This file defines a pair of templates (TreeInRoot and TreeInNode) that implement an intrusive binary tree.

Overview

TreeInRoot and TreeInNode provide a simple API to allow classes to provide a basic Tree <-> Node relationship (1 Tree Root holding many Nodes) as a Binary Tree.

Note that this class makes no attempt to "balence" the tree, but is designed that it can be derived from by a class to implement any needed balencing.

To create this relationship, the class to act as the tree root derives from the template TreeInRoot, and the class to act as the Node from TreeInNode, both with a first parameter of the class name of the List clase, a second parameter of the Node clasee, and a 3rd type parameter for the type for the Key to use in searching the tree. There is an optional integral 4rd parameter to allow the classes to inherent from these multiple times if you need to represent multiple simultaneous relationships. This inheretance should be public, or you need to add the TreeInRoot and TreeInNode templates as friends.

At the point of decleration, both classes need to be declared, so you will typically have a forward of the other class before the definition of the class. At the point of usage of members, generally the full definition of both classes is needed to instance the code for the template.

The user of the class will need to define two member functions to configure the tree. int TreeInRoot::compare(N& node1, N& node2) const; and int TreeInRoot::compare(N& node, K key) const;

Inside this file, the following types have the following meanings:

R: The "user" type that will be derived from TreeInRoot

N: The "user" type that will be derived from TreeInNode

K: The "user" type that represents the Key for the tree.

n: The integer parameter for the template to allow multiple useage

List: The particular instance of TreeInRoot<R, N, K, n> being used

Node: The particular instance of TreeInNode<R, N, K, n> being used

node: will have type N*, to be used when walking the list.

Invarients
  • if root->base_ != NULL
  • root->base_->root_ == &root
  • root->base_->parent_ == NULL
  • if node->root_ == NULL
  • node->parent_ == NULL
  • node->left_ == NULL
  • node->right_ == NULL
  • if node->root_ != NULL and node->parent_ == NULL
  • node->root_->base_ == &node
  • if node->parent_ != NULL
  • Either node->parent_->left_ or node->parent_->right_ == &node
  • if node->left_ != NULL
  • node->left_->parent_ = &node
  • node->left_->