Aleph-w  1.5a.2
Biblioteca general de algoritmos y estructuras de datos
 Todo Clases Archivos Funciones Variables 'typedefs' Enumeraciones Amigas Grupos Páginas
tpl_binTree.H
1 
2 # ifndef TPL_BINTREE_H
3 # define TPL_BINTREE_H
4 
5 # include <tpl_binTreeOps.H>
6 
7 using namespace Aleph;
8 
9 namespace Aleph {
10 
29  template <template <typename> class NodeType, typename Key, class Compare>
30 class GenBinTree
31 {
32 public:
33 
34  typedef NodeType<Key> Node;
35 
36 private:
37 
38  Node headNode;
39  Node * head;
40  Node *& root;
41  Compare & cmp;
42 
43  GenBinTree(const GenBinTree & ) = delete;
44 
45  GenBinTree & operator = (const GenBinTree &) = delete;
46 
47 public:
48 
49  void swap(GenBinTree & tree)
50  {
51  std::swap(root, tree.root);
52  std::swap(cmp, tree.cmp);
53  }
54 
56  Compare & key_comp() { return cmp; }
57 
59  Compare & get_compare() { return key_comp(); }
60 
61  GenBinTree(Compare & __cmp)
62  : head(&headNode), root(headNode.getR()), cmp(__cmp)
63  {
64  // empty
65  }
66 
67  GenBinTree(Compare && __cmp)
68  : head(&headNode), root(headNode.getR()), cmp(__cmp)
69  {
70  // empty
71  }
72 
82  Node * search(const Key & key)
83  {
84  return BinTree_Operation<Node, Compare>(cmp).search(root, key);
85  }
86 
87  virtual ~GenBinTree() { /* Empty */ }
88 
89  bool verify() { return check_binary_search_tree<Node, Compare>(root); }
90 
92  Node*& getRoot() { return root; }
93 
94  bool verifyBin()
95  {
96  return check_binary_search_tree<Node, Compare>(root);
97  }
98 
107  Node * insert(Node *p)
108  {
109  return BinTree_Operation<Node, Compare>(cmp).insert(root, p);
110  }
111 
120  Node * insert_dup(Node *p)
121  {
122  return BinTree_Operation<Node, Compare>(cmp).insert_dup(root, p);
123  }
124 
139  Node * search_or_insert(Node *p)
140  {
142  }
143 
159  bool split(const Key & key, GenBinTree & l, GenBinTree & r)
160  {
162  split_key_rec(root, key, l.root, r.root);
163  }
164 
177  bool split_dup(const Key & key, GenBinTree & l, GenBinTree & r)
178  {
180  split_key_dup_rec(root, key, l.root, r.root);
181  }
182 
194  Node * remove(const Key & key)
195  {
196  Node * ret = BinTree_Operation<Node, Compare>(cmp).remove(root, key);
197 
198  return ret != Node::NullPtr ? ret : NULL;
199  }
200 
212  void join(GenBinTree & tree, GenBinTree & dup)
213  {
214  root = BinTree_Operation<Node, Compare>(cmp).join(root, tree.root, dup);
215  tree.root = Node::NullPtr;
216  }
217 };
234  template <typename Key, class Compare = Aleph::less<Key> >
235 class BinTree : public GenBinTree<BinNode, Key, Compare>
236 {
237 public:
238 
239  BinTree(Compare && cmp = Compare())
240  : GenBinTree<BinNode, Key, Compare>(std::move(cmp))
241  {
242  // empty
243  }
244 
245  BinTree(Compare & cmp)
247  {
248  // empty
249  }
250 };
251 
268  template <typename Key, class Compare = Aleph::less<Key> >
269 class BinTreeVtl : public GenBinTree<BinNodeVtl, Key, Compare>
270 {
271 public:
272 
273  BinTreeVtl(Compare && cmp = Compare())
274  : GenBinTree<BinNodeVtl, Key, Compare>(std::move(cmp))
275  {
276  // empty
277  }
278 
279  BinTreeVtl(Compare & cmp)
281  {
282  // empty
283  }
284 };
285 
286 } // end namespace Aleph
287 # endif /* TPL_BINTREE_H */
288 
Compare & get_compare()
Definition: tpl_binTree.H:59
Compare & key_comp()
Retorna una referencia al criterio de comparación.
Definition: tpl_binTree.H:56
Node *& getRoot()
Retorna la raíz del árbol binario de búsqueda.
Definition: tpl_binTree.H:92
Definition: tpl_binTree.H:235
Node * insert(Node *p)
Definition: tpl_binTree.H:107
void join(GenBinTree &tree, GenBinTree &dup)
Definition: tpl_binTree.H:212
Definition: tpl_binTree.H:30
void split_key_dup_rec(Node *root, const typename Node::key_type &key, Node *&ts, Node *&tg)
Definition: tpl_binNodeUtils.H:2121
bool split_key_rec(Node *root, const typename Node::key_type &key, Node *&ts, Node *&tg)
Definition: tpl_binNodeUtils.H:2067
bool split_dup(const Key &key, GenBinTree &l, GenBinTree &r)
Definition: tpl_binTree.H:177
Node * search_or_insert(Node *p)
Definition: tpl_binTree.H:139
Node * search(const Key &key)
Definition: tpl_binTree.H:82
Definition: tpl_binTree.H:269
bool split(const Key &key, GenBinTree &l, GenBinTree &r)
Definition: tpl_binTree.H:159
Node * insert_dup(Node *p)
Definition: tpl_binTree.H:120
Definition: tpl_binTreeOps.H:25

Leandro Rabindranath León