00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 # ifndef TPL_BINTREE_H
00045 # define TPL_BINTREE_H
00046
00047 # include <tpl_binNodeUtils.H>
00048
00049 using namespace Aleph;
00050
00051 namespace Aleph {
00052
00071 template <template <typename> class NodeType, typename Key, class Compare>
00072 class GenBinTree
00073 {
00074
00075 public:
00076
00077 typedef NodeType<Key> Node;
00078
00079 private:
00080
00081
00082 private:
00083
00084 Node headNode;
00085 Node * head;
00086 Node *& root;
00087
00088 GenBinTree(const GenBinTree & );
00089
00090 GenBinTree & operator =(const GenBinTree &);
00091 public:
00092
00093 GenBinTree() : head(&headNode), root(headNode.getR()) { }
00103 Node * search(const Key & key)
00104 {
00105 return searchInBinTree <Node, Compare>(root, key);
00106 }
00107 virtual ~GenBinTree() { }
00109 Node*& getRoot() { return root; }
00110 bool verifyBin()
00111 {
00112 return check_binary_search_tree<Node, Compare>(root);
00113 }
00114
00115 void reset() { new (this) GenBinTree; }
00124 Node * insert(Node *p)
00125 {
00126
00127 I(p != Node::NullPtr);
00128 I((LLINK(p) == Node::NullPtr) and(RLINK(p) == Node::NullPtr));
00129
00130 return insert_in_binary_search_tree<Node, Compare>(root, p);
00131 }
00147 bool split(const Key & key, GenBinTree & l, GenBinTree & r)
00148 {
00149
00150 I(l.root == Node::NullPtr and r.root == Node::NullPtr);
00151
00152 return split_key_rec<Node, Compare>(root, key, l.root, r.root);
00153 }
00165 Node * remove(const Key & key)
00166 {
00167 return remove_from_search_binary_tree<Node, Compare>(root, key);
00168 }
00180 void join(GenBinTree & tree, GenBinTree & dup)
00181 {
00182 root = Aleph::join<Node, Compare> (root, tree.root, dup);
00183
00184 tree.root = Node::NullPtr;
00185 }
00186 };
00187
00204 template <typename Key, class Compare = Aleph::less<Key> >
00205 class BinTree : public GenBinTree<BinNode, Key, Compare>
00206 { };
00207
00224 template <typename Key, class Compare = Aleph::less<Key> >
00225 class BinTreeVtl : public GenBinTree<BinNodeVtl, Key, Compare>
00226 { };
00227
00228 }
00229 # endif
00230