Intrusive Containers
|
Intrusive Binary Tree (unbalanced). More...
#include "Container.h"
Go to the source code of this file.
Classes | |
class | TreeInNode< R, N, K, s, n > |
Intrusive Binary Tree, Node. More... | |
class | TreeInRoot< R, N, K, s, n > |
Intrusive Binary Tree, Root. More... | |
Intrusive Binary Tree (unbalanced).
This file defines a pair of templates (TreeInRoot and TreeInNode) that implement an intrusive binary tree.
MIT License:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 "balance" the tree, but is designed that it can be derived from by a class to implement any needed balancing.
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 class, a second parameter of the Node class, 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 inheritance should be public, or you need to add the TreeInRoot and TreeInNode templates as friends.
At the point of declaration, 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 usage
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.
Given: