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_dynSetTree.H
1 
2 # ifndef TPL_DYNSETTREE_H
3 # define TPL_DYNSETTREE_H
4 
5 # include <tpl_binNodeUtils.H>
6 # include <tpl_binNodeXt.H>
7 # include <tpl_binTree.H>
8 # include <tpl_treap.H>
9 # include <tpl_treapRk.H>
10 # include <tpl_avl.H>
11 # include <tpl_rand_tree.H>
12 # include <tpl_rb_tree.H>
13 # include <tpl_splay_tree.H>
14 # include <tpl_nodePool.H>
15 
16 using namespace Aleph;
17 
18 namespace Aleph {
19 
29  template <
30  typename Key,
31  template <typename, class> class Tree = Avl_Tree,
32  class Compare = Aleph::less<Key>
33  >
35 {
36 public:
37 
40  typedef typename Tree<Key, Compare>::Node Node;
41 
42 private:
43 
44  static const size_t dim = 13;
45 
46  typedef Tree<Key, Compare> Tree_Type;
47 
48  mutable Tree<Key, Compare> tree;
49  size_t num_nodes;
50  Node_Pool<Node> node_pool;
51 
52 public:
53 
54  typedef DynSetTree Set_Type;
55 
56  typedef Key Item_Type;
57 
58  typedef Key Key_Type;
59 
65  void swap(DynSetTree & dset)
66  {
67  tree.swap(dset.tree);
68  std::swap(num_nodes, dset.num_nodes);
69  }
70 
72  DynSetTree(Compare && cmp = Compare())
73  : tree(std::move(cmp)), num_nodes(0), node_pool(dim)
74  {
75  /* empty */
76  }
77 
78  DynSetTree(Compare & cmp)
79  : tree(cmp), num_nodes(0), node_pool(dim)
80  {
81  /* empty */
82  }
83 
85  DynSetTree(const DynSetTree & srcTree)
86  : tree(srcTree.tree.get_compare()), num_nodes(srcTree.num_nodes),
87  node_pool(srcTree.dim)
88  {
89  Node * srcRoot = srcTree.tree.getRoot();
90  try
91  {
92  tree.getRoot() = copyRec(srcRoot);
93  }
94  catch (...)
95  {
96  num_nodes = 0;
97  throw;
98  }
99  }
100 
102  {
103  list.for_each([this] (const Key & k) { insert(k); });
104  }
105 
106  DynSetTree(DynSetTree && srcTree) : num_nodes(0), node_pool(dim)
107  {
108  swap(srcTree);
109  }
110 
112  void empty()
113  {
114  destroyRec(tree.getRoot());
115  num_nodes = 0;
116  }
117 
118  DynSetTree & operator = (const DynList<Key> & list)
119  {
120  return *this = DynSetTree(list);
121  }
122 
124  DynSetTree & operator = (const DynSetTree & srcTree)
125  {
126  if (this == &srcTree)
127  return *this;
128 
129  Node *src_root = (Node*) const_cast<DynSetTree&>(srcTree).tree.getRoot();
130 
131  empty();
132 
133  tree.getRoot() = copyRec(src_root);
134  num_nodes = srcTree.num_nodes;
135 
136  return *this;
137  }
138 
140  DynSetTree & operator = (DynSetTree && srcTree)
141  {
142  swap(srcTree);
143  return *this;
144  }
145 
147  virtual ~DynSetTree()
148  {
149  destroyRec(tree.getRoot());
150  }
151 
152 private:
153 
154  Key * __insert(Node * p)
155  {
156  if (tree.search_or_insert(p) != p)
157  {
158  node_pool.deallocate(p);
159  return NULL;
160  }
161 
162  ++num_nodes;
163 
164  return &p->get_key();
165  }
166 
167 public:
168 
177  Key * insert(const Key & key)
178  {
179  return __insert(node_pool.allocate(key));
180  }
181 
182  Key * insert(Key && key)
183  {
184  return __insert(node_pool.allocate(std::move(key)));
185  }
186 
187  Key * append(const Key & key)
188  {
189  return __insert(node_pool.allocate(key));
190  }
191 
192  Key * append(Key && key)
193  {
194  return __insert(node_pool.allocate(std::move(key)));
195  }
196 
197 private:
198 
199  Key * __search_or_insert(Node * p)
200  {
201  Node * q = tree.search_or_insert(p);
202  if (q != p)
203  node_pool.deallocate(p);
204  else
205  ++num_nodes;
206 
207  return &q->get_key();
208  }
209 
210 
211 public:
212 
225  Key * search_or_insert(const Key & key)
226  {
227  return __search_or_insert(node_pool.allocate(key));
228  }
229 
230  Key * search_or_insert(Key && key)
231  {
232  return __search_or_insert(node_pool.allocate(std::move(key)));
233  }
234 
235 private:
236 
237  Key * __insert_dup(Node * q)
238  {
239  Node * p = tree.insert_dup(q);
240  ++num_nodes;
241  return &p->get_key();
242  }
243 
244 public:
245 
246  Key * insert_dup(const Key & key)
247  {
248  return __insert_dup(node_pool.allocate(key));
249  }
250 
251  Key * insert_dup(Key && key)
252  {
253  return __insert_dup(node_pool.allocate(std::move(key)));
254  }
255 
257  Key * put(const Key & key)
258  {
259  return insert(key);
260  }
261 
262  Key * put(Key && key)
263  {
264  return insert(std::move(key));
265  }
266 
274  size_t remove(const Key & key)
275  {
276  Node * p = static_cast<Node*>(tree.remove(key));
277 
278  if (p == NULL)
279  return num_nodes;
280 
281  node_pool.deallocate(p);
282 
283  return --num_nodes;
284  }
285 
287  bool exist(const Key & key) const
288  {
289  return const_cast<DynSetTree&>(*this).search(key) != NULL;
290  }
291 
292  bool has(const Key & key) const
293  {
294  return exist(key);
295  }
296 
297  bool contains(const Key & key) const
298  {
299  return exist(key);
300  }
301 
316  Key & find(const Key & key) throw(std::exception, std::domain_error)
317  {
318  Node * node = static_cast<Node*>(tree.search(key));
319 
320  if (node == NULL)
321  throw std::domain_error("key not found");
322 
323  return node->get_key();
324  }
325 
340  std::pair<int, Key*> find_position(const Key & key) const
341  {
342  if (num_nodes == 0)
343  return std::pair<int, Key*> (0, NULL);
344 
345  std::pair<int, Node*> p = tree.find_position(key);
346 
347  return std::pair<int, Key*> (p.first, &p.second->get_key());
348  }
349 
364  Key * search(const Key & key) const
365  throw(std::exception, std::domain_error)
366  {
367  Node * node = static_cast<Node*>(tree.search(key));
368 
369  if (node == NULL)
370  return NULL;
371 
372  return &(node->get_key());
373  }
374 
377  const Key & min() const
378  {
379  if (num_nodes == 0)
380  throw std::domain_error("set is empty");
381 
382  return find_min(tree.getRoot())->get_key();
383  }
384 
386  const Key & get_first() { return min(); }
387 
390  const Key & max() const
391  {
392  if (num_nodes == 0)
393  throw std::domain_error("set is empty");
394 
395  return find_max(tree.getRoot())->get_key();
396  }
397 
399  const Key & get_last() { return max(); }
400 
402  const Key & get()
403  {
404  return max();
405  }
406 
408  const size_t & size() const { return num_nodes; }
409 
411  bool is_empty() const { return num_nodes == 0; }
412 
415  size_t internal_path_length() const
416  {
417  return Aleph::internal_path_length(tree.getRoot());
418  }
419 
420  Node * get_root_node() const { return tree.getRoot(); }
421 
422  const Key & get_root() const
423  {
424  if (num_nodes == 0)
425  throw std::domain_error("Tree is empty");
426  return KEY(tree.getRoot());
427  }
428 
430  size_t height() const { return computeHeightRec(tree.getRoot()); }
431 
434  template <class Op>
435  void for_each_in_preorder(void (*visitFct)(Node*, int, int))
436  {
437  Node * root = static_cast<Node*>(tree.getRoot());
438  preOrderRec(root, visitFct);
439  }
440 
453  long position(const Key & key) const
454  {
455  std::pair<long, Node*> p = tree.position(key);
456  return p.first;
457  }
458 
464  Key & select(const size_t & i)
465  {
466  return tree.select(i)->get_key();
467  }
468 
469  const Key & select(const size_t & i) const
470  {
471  return tree.select(i)->get_key();
472  }
473 
474  Key & operator () (const size_t & i)
475  {
476  return select(i);
477  }
478 
479  Key & access (const size_t & i)
480  {
481  return select(i);
482  }
483 
484  bool verify()
485  {
486  return tree.verify() and check_binary_search_tree(tree.getRoot());
487  }
488 
489 private:
490 
491  template <class Key_Op>
492 struct Node_Op
493 {
494  Key_Op & key_op;
495 
496  Node_Op(Key_Op & __key_op) : key_op(__key_op) { /* empty */ }
497 
498  Node_Op(Key_Op && __key_op) : key_op(__key_op)
499  {
500  /* empty */
501  }
502 
503  void operator () (Node * root)
504  {
505  I(root != NULL);
506  key_op(KEY(root));
507  }
508 };
509 
510 public:
511 
536  template <class Key_Op>
537  void for_each_preorder(Key_Op & key_op)
538  {
539  Node * root = (Node *) tree.getRoot();
540 
541  Node_Op <Key_Op> node_op(const_cast<Key_Op&>(key_op));
542 
543  For_Each_Preorder<Node, Node_Op<Key_Op>> () (root, node_op);
544  }
545 
547  template <class Key_Op>
548  void for_each_preorder(Key_Op && key_op = Key_Op())
549  {
550  for_each_preorder<Key_Op>(key_op);
551  }
552 
577  template <class Key_Op>
578  void for_each_inorder(Key_Op & key_op)
579  {
580  Node * root = (Node *) tree.getRoot();
581 
582  Node_Op <Key_Op> node_op(const_cast<Key_Op&>(key_op));
583 
584  For_Each_In_Order<Node, Node_Op<Key_Op>> () (root, node_op);
585  }
586 
588  template <class Key_Op>
589  void for_each_inorder(Key_Op && key_op = Key_Op())
590  {
591  for_each_inorder<Key_Op>(key_op);
592  }
593 
618  template <class Key_Op>
619  void for_each_postorder(Key_Op & key_op)
620  {
621  Node * root = (Node *) tree.getRoot();
622 
623  Node_Op <Key_Op> node_op(const_cast<Key_Op&>(key_op));
624 
625  For_Each_Postorder<Node, Node_Op <Key_Op>> () (root, node_op);
626  }
627 
629  template <class Key_Op>
630  void for_each_postorder(Key_Op && key_op = Key_Op())
631  {
632  for_each_postorder<Key_Op>(key_op);
633  }
634 
651  {
652  BinTree_Operation <Node, Compare> (tree.get_compare()).
653  join(tree.getRoot(), t.tree.getRoot(), dup.tree.getRoot());
654 
655  t.num_nodes = 0;
656  t.tree.getRoot() = Node::NullPtr;
657 
658  dup.num_nodes = COUNT(dup.tree.getRoot());
659  num_nodes = COUNT(tree.getRoot());
660 
661  return *this;
662  }
663 
666  {
667  return join(t, dup);
668  }
669 
683  {
684  tree.join_dup(t.tree);
685  t.num_nodes = 0;
686  t.tree.getRoot() = Node::NullPtr;
687  num_nodes = COUNT(tree.getRoot());
688  return *this;
689  }
690 
706  bool split_key(const Key & key, DynSetTree & l, DynSetTree & r)
707  {
708  if (not split_key_rec_xt<Node, Compare>(tree.getRoot(), key,
709  l.tree.getRoot(), r.tree.getRoot()))
710  return false;
711 
712  tree.getRoot() = Node::NullPtr;
713  num_nodes = 0;
714  l.num_nodes = COUNT(l.tree.getRoot());
715  r.num_nodes = COUNT(r.tree.getRoot());
716 
717  return true;
718  }
719 
733  void split_pos(const size_t pos, DynSetTree & l, DynSetTree & r)
734  {
735  split_pos_rec(tree.getRoot(), pos, l.tree.getRoot(), r.tree.getRoot());
736 
737  tree.getRoot() = Node::NullPtr;
738  num_nodes = 0;
739  l.num_nodes = COUNT(l.tree.getRoot());
740  r.num_nodes = COUNT(r.tree.getRoot());
741  }
742 
755  void split_key_dup(const Key & key, DynSetTree & l, DynSetTree & r)
756  {
757  split_key_dup_rec_xt<Node,Compare>(tree.getRoot(), key,
758  l.tree.getRoot(), r.tree.getRoot());
759 
760  tree.getRoot() = Node::NullPtr;
761  num_nodes = 0;
762  l.num_nodes = COUNT(l.tree.getRoot());
763  r.num_nodes = COUNT(r.tree.getRoot());
764  }
765 
766  class Iterator
767  {
768  protected:
769 
770  mutable DynSetTree * tree_ptr;
771  mutable Node * curr;
772  mutable int curr_pos;
773 
774  static const int Pos_Not_Current = -1;
775  static const int Pos_Empty_Container = -2;
776  static const int Pos_Not_Updated = -3;
777 
778  private:
779 
780  bool is_container_empty() const
781  {
782  return tree_ptr->size() == 0;
783  }
784 
785  bool pos_updated() const
786  {
787  return curr_pos != Pos_Not_Updated;
788  }
789 
790  bool curr_updated() const
791  {
792  return curr != NULL;
793  }
794 
795  bool is_updated()
796  {
797  return pos_updated() and curr_updated();
798  }
799 
800  void update_pos() const
801  {
802  I(curr != NULL);
803 
804  curr_pos = tree_ptr->position(curr->get_key());
805  }
806 
807  void update_curr() const
808  {
809  I(curr_pos != Pos_Not_Updated);
810 
811  if (curr_pos == Pos_Empty_Container or curr_pos == Pos_Not_Current or
812  curr_pos == tree_ptr->size())
813  return;
814 
815  curr = Node::key_to_node(tree_ptr->select(curr_pos));
816  }
817 
818  public:
819 
821  Iterator() : tree_ptr(NULL), curr(NULL), curr_pos(Pos_Not_Current)
822  {
823  /* empty */
824  }
825 
827  Iterator(const DynSetTree & tree)
828  : tree_ptr(&const_cast<DynSetTree&>(tree)), curr(NULL)
829  {
830  curr_pos = is_container_empty() ? Pos_Empty_Container : 0;
831  }
832 
834  void set_pos(size_t pos)
835  {
836  if (tree_ptr == NULL)
837  std::domain_error("There is not tree associated to iterator");
838 
839  curr_pos = pos;
840  curr = Node::key_to_node(tree_ptr->select(curr_pos));
841  }
842 
844  void set_key(const Key & key)
845  {
846  if (tree_ptr == NULL)
847  std::domain_error("There is not tree associated to iterator");
848 
849  std::pair<int, Node*> p = tree_ptr->find_position(key);
850  curr = Node::key_to_node(KEY(p));
851  curr_pos = p.first;
852  }
853 
855  Iterator (const Iterator & itor)
856  : tree_ptr(itor.tree_ptr), curr(itor.curr), curr_pos(itor.curr_pos)
857  {
858  // Empty
859  }
860 
862  Iterator & operator = (const Iterator & itor)
863  {
864  if (this == &itor)
865  return *this;
866 
867  tree_ptr = itor.tree_ptr;
868  curr = itor.curr;
869  curr_pos = itor.curr_pos;
870 
871  return *this;
872  }
873 
875  void reset_first()
876  {
877  curr = NULL;
878  curr_pos = is_container_empty() ? Pos_Empty_Container : 0;
879  }
880 
882  void reset_last()
883  {
884  curr = NULL;
885  curr_pos =
886  is_container_empty() ? Pos_Empty_Container : tree_ptr->size() - 1;
887  }
888 
895  void reset_to_key (const Key & key)
896  {
897  std::pair<long, Key*> p = tree_ptr->position(key);
898  curr_pos = p.first;
899  }
900 
907  void reset_to_node (Node * node)
908  {
909  curr = node;
910  curr_pos = -2;
911  }
912 
914  void reset_to_pos (size_t pos)
915  {
916  curr = NULL;
917  curr_pos = pos;
918  }
919 
921  Key & get_current() const
922  {
923  if (not curr_updated())
924  update_curr();
925 
926  return KEY(curr);
927  }
928 
930  Key & get_curr() const
931  {
932  return get_current();
933  }
934 
945  size_t get_current_position() const
946  throw (std::exception, std::underflow_error, std::overflow_error)
947  {
948  if (not pos_updated())
949  update_pos();
950 
951  if (curr_pos < -1 )
952  throw std::range_error ("DynSetTree::Iterator has not current");
953 
954  if (curr_pos > COUNT (tree_ptr->getRoot() ) )
955  throw std::range_error ("DynSetTree::iterator has not current");
956 
957  return curr_pos;
958  }
959 
962  bool has_current() const
963  {
964  if (not pos_updated())
965  update_pos();
966 
967  return curr_pos >= 0 and curr_pos < tree_ptr->size();
968  }
969 
972  bool has_curr() const
973  {
974  return has_current();
975  }
976 
978  void prev() throw (std::exception, std::underflow_error)
979  {
980  if (not has_current() )
981  throw std::underflow_error ("DynSetTree::Iterator has not current");
982 
983  --curr_pos;
984  curr = NULL;
985  }
986 
988  void next() throw (std::exception, std::overflow_error)
989  {
990  if (not has_current() )
991  throw std::underflow_error ("DynSetTree::Iterator has not current");
992 
993  ++curr_pos;
994  curr = NULL;
995  }
996 
999  Key del()
1000  {
1001  if (not has_current() )
1002  throw std::underflow_error ("DynSetTree::Iterator has not current");
1003 
1004  if (not curr_updated())
1005  update_curr();
1006 
1007  Key ret_val = curr->get_key();
1008  tree_ptr->remove(ret_val);
1009 
1010  curr = NULL;
1011 
1012  return ret_val;
1013  }
1014 
1016  bool operator == (const Iterator & itor) const
1017  {
1018  if (is_container_empty() and itor.is_container_empty())
1019  return true;
1020 
1021  if (pos_updated() and itor.pos_updated())
1022  return curr_pos == itor.curr_pos;
1023 
1024  if (curr_updated() and itor.curr_updated())
1025  return curr == itor.curr;
1026 
1027  if (not pos_updated())
1028  {
1029  update_pos();
1030  return curr_pos == itor.curr_pos;
1031  }
1032 
1033  itor.update_pos();
1034 
1035  return curr_pos == itor.curr_pos;
1036  }
1037 
1039  bool operator != (const Iterator & itor) const
1040  {
1041  return not (*this == itor);
1042  }
1043  }; // end class Iterator
1044 
1059  template <class Operation>
1060  bool traverse(Operation & op)
1061  {
1062  return Aleph::traverse(tree.getRoot(), [&op] (Node * p)
1063  {
1064  return op(p->get_key());
1065  });
1066  }
1067 
1068  template <class Operation>
1069  bool traverse(Operation && op = Operation())
1070  {
1071  return traverse<Operation>(op);
1072  }
1073 
1074  template <class Operation>
1075  bool traverse(Operation & op) const
1076  {
1077  return Aleph::traverse(tree.getRoot(), [&op] (Node * p)
1078  {
1079  return op(p->get_key());
1080  });
1081  }
1082 
1083  template <class Operation>
1084  bool traverse(Operation && op = Operation()) const
1085  {
1086  return traverse<Operation>(op);
1087  }
1088 
1089  Functional_Methods(Key);
1090  Generic_Keys(Key);
1091  Equal_To_Method(DynSetTree);
1092 };
1093 
1094 
1095 # define SETTREE_ITOR(Name, Key, Cmp) \
1096  class Iterator : public DynSetTree<Key, Name, Cmp>::Iterator \
1097  { \
1098  public: \
1099  Iterator() : DynSetTree<Key, Name, Cmp>::Iterator() \
1100  { /* empty */ } \
1101  \
1102  Iterator(DynSetTree<Key, Name, Cmp> & tree) \
1103  : DynSetTree<Key, Name, Cmp>::Iterator(tree) \
1104  { /* empty */ } \
1105  };
1106 
1107 
1114  template <typename Key, class Compare = Aleph::less<Key>>
1115 class DynSetBinTree : public DynSetTree<Key, BinTree, Compare>
1116  { /* empty */ };
1117 
1118 
1125  template <typename Key, class Compare = Aleph::less<Key>>
1126 class DynSetAvlTree : public DynSetTree<Key, Avl_Tree, Compare>
1127  { /* empty */ };
1128 
1129 
1136  template <typename Key, class Compare = Aleph::less<Key>>
1137 class DynSetSplayTree : public DynSetTree<Key, Splay_Tree, Compare>
1138  { /* empty */ };
1139 
1140 
1147  template <typename Key, class Compare = Aleph::less<Key>>
1148 class DynSetRandTree : public DynSetTree<Key, Rand_Tree, Compare>
1149 {
1150 public:
1151 
1152  class Iterator : public DynSetTree<Key, Rand_Tree, Compare>::Iterator
1153  {
1154  public:
1156  { /* empty */ }
1157 
1160  { /* empty */ }
1161  };
1162 
1163 
1164 };
1165 
1166 
1173  template <typename Key, class Compare = Aleph::less<Key>>
1174 class DynSetTreap : public DynSetTree<Key, Treap, Compare>
1175  { /* empty */ };
1176 
1183  template <typename Key, class Compare = Aleph::less<Key>>
1184 class DynSetTreapRk : public DynSetTree<Key, Treap_Rk, Compare>
1185 {
1186 public:
1187  SETTREE_ITOR(Treap_Rk, Key, Compare);
1188 };
1189 
1190 
1191 
1198  template <typename Key, class Compare = Aleph::less<Key>>
1199 class DynSetRbTree : public DynSetTree<Key, Rb_Tree, Compare>
1200  { /* empty */ };
1201 
1202 
1203 } // end namespace Aleph
1204 
1205 # endif /* TPL_DYNSETTREE_H */
1206 
void for_each_inorder(Key_Op &key_op)
Definition: tpl_dynSetTree.H:578
Definition: tpl_dynSetTree.H:766
size_t get_current_position() const
Definition: tpl_dynSetTree.H:945
Definition: tpl_treapRk.H:902
Definition: tpl_nodePool.H:19
Definition: tpl_binNodeUtils.H:407
Tree< Key, Compare >::Node Node
Definition: tpl_dynSetTree.H:40
void set_key(const Key &key)
Coloca el iterador en la clave key.
Definition: tpl_dynSetTree.H:844
DynSetTree & join(DynSetTree &t, DynSetTree &dup)
Definition: tpl_dynSetTree.H:650
size_t remove(const Key &key)
Definition: tpl_dynSetTree.H:274
const size_t & size() const
Retorna la cardinalidad del conjunto.
Definition: tpl_dynSetTree.H:408
Definition: ahFunction.H:145
bool operator!=(const Iterator &itor) const
Retorna true si *this no es igual a itor.
Definition: tpl_dynSetTree.H:1039
Iterator()
Constructor vacío; no tiene sentido si no se asigna un treap.
Definition: tpl_dynSetTree.H:821
DynSetTree(const DynSetTree &srcTree)
Instancia un conjunto dinámico copia de srcTree.
Definition: tpl_dynSetTree.H:85
void reset_to_node(Node *node)
Definition: tpl_dynSetTree.H:907
Definition: tpl_dynSetTree.H:1115
const Key & get_last()
Definition: tpl_dynSetTree.H:399
Node * find_max(Node *root)
Definition: tpl_binNodeUtils.H:1784
#define COUNT(p)
Definition: tpl_binNodeXt.H:34
void reset_last()
Reinicia el iterador al último nodo (mayor) del treap.
Definition: tpl_dynSetTree.H:882
virtual ~DynSetTree()
Destructor; todos los elementos son liberados.
Definition: tpl_dynSetTree.H:147
void split_pos(const size_t pos, DynSetTree &l, DynSetTree &r)
Definition: tpl_dynSetTree.H:733
Definition: tpl_dynSetTree.H:1126
void set_pos(size_t pos)
Coloca el iterador en la posición pos.
Definition: tpl_dynSetTree.H:834
void reset_first()
Reinicia el iterador al primer nodo (menor) del treap.
Definition: tpl_dynSetTree.H:875
Key * search(const Key &key) const
Definition: tpl_dynSetTree.H:364
Key & select(const size_t &i)
Definition: tpl_dynSetTree.H:464
std::pair< int, Key * > find_position(const Key &key) const
Definition: tpl_dynSetTree.H:340
size_t internal_path_length() const
Definition: tpl_dynSetTree.H:415
void reset_to_key(const Key &key)
Definition: tpl_dynSetTree.H:895
size_t internal_path_length(Node *p)
Definition: tpl_binNodeUtils.H:1259
Node * find_min(Node *root)
Definition: tpl_binNodeUtils.H:1764
void for_each_preorder(Key_Op &&key_op=Key_Op())
Definition: tpl_dynSetTree.H:548
void swap(DynSetTree &dset)
Definition: tpl_dynSetTree.H:65
Key & get_current() const
Retorna el nodo actual.
Definition: tpl_dynSetTree.H:921
int preOrderRec(Node *root, void(*visitFct)(Node *, int, int))
Definition: tpl_binNodeUtils.H:93
Definition: tpl_binNodeUtils.H:325
Iterator(const DynSetTree &tree)
Instancia un iterador a partir del menor nodo del treap __tree.
Definition: tpl_dynSetTree.H:827
const Key & min() const
Definition: tpl_dynSetTree.H:377
void for_each_in_preorder(void(*visitFct)(Node *, int, int))
Definition: tpl_dynSetTree.H:435
Definition: tpl_dynSetTree.H:1137
const Key & max() const
Definition: tpl_dynSetTree.H:390
bool split_key(const Key &key, DynSetTree &l, DynSetTree &r)
Definition: tpl_dynSetTree.H:706
void split_key_dup(const Key &key, DynSetTree &l, DynSetTree &r)
Definition: tpl_dynSetTree.H:755
Definition: tpl_dynSetTree.H:1148
Key & find(const Key &key)
Definition: tpl_dynSetTree.H:316
size_t computeHeightRec(Node *node)
Definition: tpl_binNodeUtils.H:778
DynSetTree & join_dup(DynSetTree &t)
Definition: tpl_dynSetTree.H:682
const Key & get_first()
Definition: tpl_dynSetTree.H:386
Key & get_curr() const
Retorna el nodo actual.
Definition: tpl_dynSetTree.H:930
bool operator==(const Iterator &itor) const
Retorna true si *this está sobre el mismo nodo que itor.
Definition: tpl_dynSetTree.H:1016
void destroyRec(Node *&root)
Definition: tpl_binNodeUtils.H:798
void for_each_inorder(Key_Op &&key_op=Key_Op())
Definition: tpl_dynSetTree.H:589
bool is_empty() const
Retorna true si el conjunto está vacío.
Definition: tpl_dynSetTree.H:411
Key del()
Definition: tpl_dynSetTree.H:999
bool has_curr() const
Definition: tpl_dynSetTree.H:972
void next()
Avanza el iterador una posición hacia delante.
Definition: tpl_dynSetTree.H:988
bool exist(const Key &key) const
Retorna true si key pertenece al conjunto dinámico.
Definition: tpl_dynSetTree.H:287
void for_each_preorder(Key_Op &key_op)
Definition: tpl_dynSetTree.H:537
Definition: tpl_dynSetTree.H:34
Definition: tpl_binNodeUtils.H:172
Iterator & operator=(const Iterator &itor)
Asigna al iterador this el iterador itor.
Definition: tpl_dynSetTree.H:862
void for_each_postorder(Key_Op &&key_op=Key_Op())
Definition: tpl_dynSetTree.H:630
Definition: tpl_dynSetTree.H:1184
Node * copyRec(Node *src_root)
Definition: tpl_binNodeUtils.H:821
void prev()
Avanza el iterador una posición hacia atrás.
Definition: tpl_dynSetTree.H:978
void split_pos_rec(Node *r, const size_t i, Node *&ts, Node *&tg)
Definition: tpl_binNodeXt.H:541
Definition: tpl_avl.H:573
void for_each_postorder(Key_Op &key_op)
Definition: tpl_dynSetTree.H:619
Definition: tpl_dynSetTree.H:1199
bool check_binary_search_tree(Node *p)
Definition: tpl_binNodeUtils.H:1647
DynSetTree(Compare &&cmp=Compare())
Instancia un conjunto dinámico vacío.
Definition: tpl_dynSetTree.H:72
long position(const Key &key) const
Definition: tpl_dynSetTree.H:453
Definition: ahDry.H:13
size_t height() const
Calcula y retorna la altura del árbol binario de búsqueda.
Definition: tpl_dynSetTree.H:430
Key * search_or_insert(const Key &key)
Definition: tpl_dynSetTree.H:225
#define KEY(p)
Definition: tpl_binNode.H:206
Definition: tpl_dynSetTree.H:1174
bool traverse(Operation &op)
Definition: tpl_dynSetTree.H:1060
void empty()
Elimina todos los elementos del conjunto.
Definition: tpl_dynSetTree.H:112
Key * put(const Key &key)
Seudo sinonimo de insert; no retorna ningún valor.
Definition: tpl_dynSetTree.H:257
void reset_to_pos(size_t pos)
Coloca la posición actual del iterador en la posición pos.
Definition: tpl_dynSetTree.H:914
Definition: List.H:23
Definition: tpl_binTreeOps.H:25
Iterator(const Iterator &itor)
Instancia un iterador a partir del estado del iterador itor.
Definition: tpl_dynSetTree.H:855
DynSetTree & join(DynSetTree &t, DynSetTree &&dup=DynSetTree())
Definition: tpl_dynSetTree.H:665
bool has_current() const
Definition: tpl_dynSetTree.H:962
Key * insert(const Key &key)
Definition: tpl_dynSetTree.H:177
Definition: tpl_dynSetTree.H:1152

Leandro Rabindranath León