Aleph-w  1.9
General library for algorithms and data structures
tpl_treapRk.H
1 
2 /* Aleph-w
3 
4  / \ | | ___ _ __ | |__ __ __
5  / _ \ | |/ _ \ '_ \| '_ \ ____\ \ /\ / / Data structures & Algorithms
6  / ___ \| | __/ |_) | | | |_____\ V V / version 1.9b
7  /_/ \_\_|\___| .__/|_| |_| \_/\_/ https://github.com/lrleon/Aleph-w
8  |_|
9 
10  This file is part of Aleph-w library
11 
12  Copyright (c) 2002-2018 Leandro Rabindranath Leon & Alejandro Mujica
13 
14  This program is free software: you can redistribute it and/or modify
15  it under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  This program is distributed in the hope that it will be useful, but
20  WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  General Public License for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with this program. If not, see <https://www.gnu.org/licenses/>.
26 */
27 # ifndef TPL_TREAPRK_H
28 # define TPL_TREAPRK_H
29 
30 # include <gsl/gsl_rng.h>
31 # include <ahFunction.H>
32 # include <tpl_binTreeOps.H>
33 # include <ran_array.h>
34 # include <treapNode.H>
35 
36 using namespace Aleph;
37 
38 namespace Aleph {
39 
40 class TreapRkNode_Data
41 {
42  unsigned long priority;
43 
44  unsigned long count;
45 
46 public:
47 
48  TreapRkNode_Data() noexcept : priority(Max_Priority), count(1)
49  {
50  /* empty */
51  }
52 
53  TreapRkNode_Data(SentinelCtor) noexcept : priority(Max_Priority), count(0)
54  {
55  /* empty */
56  }
57 
58  unsigned long & getPriority() noexcept { return priority; }
59 
60  unsigned long & getCount() noexcept { return count; }
61 
62  void reset() noexcept { count = 1; }
63 };
64 
65  DECLARE_BINNODE_SENTINEL(Treap_Rk_Node, 80, TreapRkNode_Data);
66 
106  template <template <class> class NodeType, class Key, class Compare>
108 {
109 public:
110 
111  using Node = NodeType<Key>;
112 
113 private:
114 
115  Node head;
116  Node * head_ptr;
117  Node *& tree_root;
118  gsl_rng * r;
119  Compare cmp;
120 
121  void init(unsigned int seed)
122  {
123  PRIO(head_ptr) = Min_Priority;
124  r = gsl_rng_alloc(gsl_rng_mt19937);
125 
126  if (r == nullptr)
127  throw std::bad_alloc();
128 
129  gsl_rng_set(r, seed % gsl_rng_max(r));
130  }
131 
132 public:
133 
135  void set_seed(unsigned long seed) noexcept { gsl_rng_set(r, seed); }
136 
138  Compare & key_comp() noexcept { return cmp; }
139 
141  Compare & get_compare() noexcept { return key_comp(); }
142 
145  Gen_Treap_Rk(unsigned long seed, Compare __cmp = Compare())
146  : head_ptr(&head), tree_root(RLINK(head_ptr)), r(nullptr), cmp(__cmp)
147  {
148  init(seed);
149  }
150 
151  Gen_Treap_Rk(Compare __cmp = Compare()) : Gen_Treap_Rk(time(nullptr), __cmp)
152  {
153  // empty
154  }
155 
156  ~Gen_Treap_Rk()
157  {
158  if (r != nullptr)
159  gsl_rng_free(r);
160  }
161 
163  void swap(Gen_Treap_Rk & tree) noexcept
164  {
165  std::swap(tree_root, tree.tree_root);
166  std::swap(cmp, tree.cmp);
167  std::swap(r, tree.r);
168  }
169 
171  Node *& getRoot() noexcept { return tree_root; }
172 
173  Node * getRoot() const noexcept { return tree_root; }
174 
181  Node * search(const Key & key) const noexcept
182  {
183  Node* ret_val = searchInBinTree(tree_root, key, cmp);
184  return ret_val == Node::NullPtr ? nullptr : ret_val;
185  }
186 
187 private:
188 
189  bool insert(Node *& root, Node * p) noexcept
190  {
191  if (root == Node::NullPtr)
192  {
193  root = p;
194  return true;
195  }
196 
197  if (cmp(KEY(p), KEY(root)))
198  {
199  if (insert(LLINK(root), p))
200  {
201  ++COUNT(root);
202  if (PRIO(LLINK(root)) < PRIO(root) )
203  root = rotate_to_right_xt(root);
204 
205  return true;
206  }
207  }
208  else if (cmp(KEY(root), KEY(p)))
209  {
210  if (insert(RLINK(root), p))
211  {
212  ++COUNT(root);
213  if (PRIO(RLINK(root)) < PRIO(root) )
214  root = rotate_to_left_xt(root);
215 
216  return true;
217  }
218  }
219 
220  return false;
221  }
222 
223  // Search or insert p. Return p if KEY(p) is not in the tree;
224  // otherwise, it returns a pointer to a node containing KEY(p)
225  Node * search_or_insert(Node *& root, Node * p) noexcept
226  {
227  if (root == Node::NullPtr)
228  return root = p;
229 
230  if (cmp(KEY(p), KEY(root)))
231  {
232  Node * ret = search_or_insert(LLINK(root), p);
233  if (ret == p) // insertion done?
234  { // yes ==> increase counter and perhaps rotate
235  ++COUNT(root);
236  if (PRIO(LLINK(root)) < PRIO(root))
237  root = rotate_to_right_xt(root);
238 
239  assert(PRIO(root) <= PRIO(LLINK(root)) and
240  PRIO(root) <= PRIO(LLINK(root)));
241  }
242 
243  return ret;
244  }
245  else if (cmp(KEY(root), KEY(p)))
246  {
247  Node * ret = search_or_insert(RLINK(root), p);
248  if (ret == p) // insertion done?
249  { // yes ==> increase counter and perhaps rotate
250  ++COUNT(root);
251  if (PRIO(RLINK(root)) < PRIO(root))
252  root = rotate_to_left_xt(root);
253 
254  assert(PRIO(root) <= PRIO(LLINK(root)) and
255  PRIO(root) <= PRIO(LLINK(root)));
256  }
257 
258  return ret;
259  }
260 
261  assert(PRIO(root) <= PRIO(LLINK(root)) and PRIO(root) <= PRIO(LLINK(root)));
262 
263  return root;
264  }
265 
266  // Return p; root could be modified
267  Node * insert_dup(Node *& root, Node * p) noexcept
268  {
269  if (root == Node::NullPtr)
270  return root = p;
271 
272  if (cmp(KEY(p), KEY(root)))
273  {
274  insert_dup(LLINK(root), p);
275  ++COUNT(root);
276  if (PRIO(LLINK(root)) < PRIO(root))
277  root = rotate_to_right_xt(root);
278  }
279  else
280  {
281  insert_dup(RLINK(root), p);
282  ++COUNT(root);
283  if (PRIO(RLINK(root)) < PRIO(root))
284  root = rotate_to_left_xt(root);
285  }
286 
287  return p;
288  }
289 
290 public:
291 
301  Node * insert(Node * p) noexcept
302  {
303  assert(p != Node::NullPtr);
304 
305  PRIO(p) = gsl_rng_get(r);
306 
307  return insert(tree_root, p) ? p : nullptr;
308  }
309 
317  Node * insert_dup(Node * p) noexcept
318  {
319  assert(p != Node::NullPtr);
320 
321  PRIO(p) = gsl_rng_get(r);
322 
323  return insert_dup(tree_root, p);
324  }
325 
326 
339  Node * search_or_insert(Node * p) noexcept
340  {
341  assert(p != Node::NullPtr);
342 
343  PRIO(p) = gsl_rng_get(r);
344 
345  return search_or_insert(tree_root, p);
346  }
347 
349  bool verify() const { return is_treap(tree_root); }
350 
351 private:
352 
353  static Node * join_exclusive(Node * t1, Node * t2) noexcept
354  {
355  if (t1 == Node::NullPtr)
356  return t2;
357 
358  if (t2 == Node::NullPtr)
359  return t1;
360 
361  if (PRIO(t1) < PRIO(t2))
362  {
363  COUNT(t1) += COUNT(t2);
364  RLINK(t1) = join_exclusive(RLINK(t1), t2);
365  return t1;
366  }
367  else
368  {
369  COUNT(t2) += COUNT(t1);
370  LLINK(t2) = join_exclusive(t1, LLINK(t2) );
371  return t2;
372  }
373  }
374 
375  Node * remove(Node *& root, const Key & key) noexcept
376  {
377  if (root == Node::NullPtr)
378  return Node::NullPtr;
379 
380  Node * ret_val;
381  if (cmp(key, KEY(root) ))
382  ret_val = remove(LLINK(root), key);
383  else if (cmp(KEY(root), key))
384  ret_val = remove(RLINK(root), key);
385  else
386  {
387  ret_val = root;
388  root = join_exclusive(LLINK(root), RLINK(root) );
389 
390  return ret_val;
391  }
392 
393  if (ret_val == Node::NullPtr)
394  return Node::NullPtr;
395 
396  --COUNT(root);
397 
398  return ret_val;
399  }
400 
401 public:
402 
409  Node * remove(const Key & key) noexcept
410  {
411  Node * ret_val = remove(tree_root, key);
412  if (ret_val == Node::NullPtr)
413  return nullptr;
414 
415  ret_val->reset();
416 
417  return ret_val;
418  }
419 
428  Node * remove(const size_t beg, const size_t end)
429  {
430  if (beg > end or end > COUNT(tree_root))
431  throw std::range_error("remove of TreapRk out of range");
432 
433  Node * before_beg, * after_end, * aux;
434 
435  Node * ret_val = tree_root;
436 
437  split_pos_rec(ret_val, end + 1, aux, after_end);
438  split_pos_rec(aux, beg, before_beg, ret_val);
439 
440  tree_root = join_exclusive(before_beg, after_end);
441 
442  return ret_val;
443  }
444 
445 private:
446 
447  static Node * remove_pos(Node *& root, const size_t pos) noexcept
448  {
449  if (pos == COUNT(LLINK(root)))
450  {
451  Node * ret_val = root;
452  root = join_exclusive(LLINK(ret_val), RLINK(ret_val));
453  return ret_val;
454  }
455 
456  --COUNT(root);
457  if (pos < COUNT(LLINK(root)))
458  return remove_pos(LLINK(root), pos);
459  else
460  return remove_pos(RLINK(root), pos - COUNT(LLINK(root)) - 1);
461  }
462 
463 public:
464 
472  Node * remove_pos(const size_t pos)
473  {
474  if (pos >= COUNT(tree_root))
475  throw std::out_of_range("infix position out of range");
476 
477  return remove_pos(tree_root, pos);
478  }
479 
487  Node * select(const size_t i) const
488  {
489  return Aleph::select(tree_root, i);
490  }
491 
493  size_t size() const noexcept { return COUNT(tree_root); }
494 
496  bool is_empty() const noexcept { return tree_root == Node::NullPtr; }
497 
507  std::pair<int, Node*> position(const Key & key) const noexcept
508  {
509  std::pair<int, Node*> ret_val;
510 
511  ret_val.first = BinTreeXt_Operation<Node, Compare>(cmp).
512  inorder_position(tree_root, key, ret_val.second);
513 
514  return ret_val;
515  }
516 
543  std::pair<int, Node*> find_position(const Key & key) const noexcept
544  {
545  std::pair<int, Node*> r(-2, nullptr);
546 
547  r.first = BinTreeXt_Operation <Node, Compare>(cmp) .
548  find_position(tree_root, key, r.second);
549 
550  return r;
551  }
552 
561  bool split_key(const Key & key, Gen_Treap_Rk & t1, Gen_Treap_Rk & t2) noexcept
562  {
563  return split_key_rec_xt(tree_root, key, t1.getRoot(), t2.getRoot());
564  }
565 
576  void
577  split_key_dup(const Key & key, Gen_Treap_Rk & t1, Gen_Treap_Rk & t2) noexcept
578  {
579  split_key_dup_rec_xt(tree_root, key, t1.getRoot(), t2.getRoot());
580  }
581 
588  void split_pos(size_t pos, Gen_Treap_Rk & t1, Gen_Treap_Rk & t2)
589  {
590  split_pos_rec(tree_root, pos, t1.getRoot(), t2.getRoot());
591  }
592 
593 private:
594 
595  void join_dup(Node *& t1, Node * t2) noexcept
596  {
597  if (t2 == Node::NullPtr)
598  return;
599 
600  Node * l = LLINK(t2), * r = RLINK(t2);
601  t2->reset();
602  t1 = insert_dup(t1, t2);
603  join_dup(t1, l);
604  join_dup(t1, r);
605  }
606 
607  void join(Node *& t1, Node * t2, Node *& dup) noexcept
608  {
609  if (t2 == Node::NullPtr)
610  return;
611 
612  Node * l = LLINK(t2), * r = RLINK(t2);
613  t2->reset();
614  ins:
615  Node * ret = insert(t1, t2);
616  if (ret == Node::NullPtr)
617  {
618  dup = insert_dup(dup, remove(t1, KEY(t2)));
619  goto ins;
620  }
621 
622  t1 = ret;
623  join(t1, l, dup);
624  join(t1, r, dup);
625  }
626 
627 public:
628 
641  void join(Gen_Treap_Rk & t, Gen_Treap_Rk & dup) noexcept
642  {
643  join(tree_root, t.tree_root, dup.tree_root);
644  t.tree_root = Node::NullPtr;
645  }
646 
655  void join_dup(Gen_Treap_Rk & t) noexcept
656  {
657  join_dup(tree_root, t.tree_root);
658  t.tree_root = Node::NullPtr;
659  }
660 
672  void join_exclusive(Gen_Treap_Rk & t) noexcept
673  {
674  tree_root = join_exclusive(tree_root, t.tree_root);
675  t.tree_root = Node::NullPtr;
676  }
677 
684  class Iterator
685  {
686  protected:
687 
688  mutable Gen_Treap_Rk * tree_ptr;
689  mutable Node * curr;
690  mutable int curr_pos;
691 
692  static const int Pos_Not_Current = -1;
693  static const int Pos_Empty_Container = -2;
694  static const int Pos_Not_Updated = -3;
695 
696  private:
697 
698  bool is_container_empty() const noexcept
699  {
700  return COUNT(tree_ptr->getRoot()) == 0;
701  }
702 
703  bool pos_updated() const noexcept
704  {
705  return curr_pos != Pos_Not_Updated;
706  }
707 
708  bool curr_updated() const noexcept
709  {
710  return curr != nullptr;
711  }
712 
713  bool is_updated() noexcept
714  {
715  return pos_updated() and curr_updated();
716  }
717 
718  void update_pos() const noexcept
719  {
720  assert(curr != nullptr);
721 
722  curr_pos = BinTreeXt_Operation<Node, Compare>(tree_ptr->cmp).
723  inorder_position(tree_ptr->getRoot(), KEY(curr), curr);
724  }
725 
726  void update_curr() const noexcept
727  {
728  assert(curr_pos != Pos_Not_Updated);
729 
730  if (curr_pos == Pos_Empty_Container or curr_pos == Pos_Not_Current or
731  curr_pos == COUNT(tree_ptr->getRoot()))
732  return;
733 
734  curr = Aleph::select(tree_ptr->getRoot(), curr_pos);
735  }
736 
737  public:
738 
739  Iterator() noexcept
740  : tree_ptr(nullptr), curr(nullptr), curr_pos(Pos_Not_Current)
741  {
742  /* empty */
743  }
744 
746  Iterator(const Gen_Treap_Rk & __tree) noexcept
747  : tree_ptr(&const_cast<Gen_Treap_Rk&>(__tree)), curr(nullptr)
748  {
749  curr_pos = is_container_empty() ? Pos_Empty_Container : 0;
750  }
751 
753  Iterator(const Gen_Treap_Rk & __tree, Node * __curr) noexcept
754  : tree_ptr(&const_cast<Gen_Treap_Rk&>(__tree)),
755  curr(__curr), curr_pos(Pos_Not_Updated)
756  {
757  // empty
758  }
759 
761  Iterator(const Gen_Treap_Rk & __tree, const size_t pos) noexcept
762  : tree_ptr(&const_cast<Gen_Treap_Rk&>(__tree)),
763  curr(nullptr), curr_pos(pos)
764  {
765  // empty
766  }
767 
768  Iterator(const Iterator & itor) noexcept
769  : tree_ptr(itor.tree_ptr), curr(itor.curr), curr_pos(itor.curr_pos)
770  {
771  // Empty
772  }
773 
774  Iterator & operator = (const Iterator & itor) noexcept
775  {
776  if (this == &itor)
777  return *this;
778 
779  tree_ptr = itor.tree_ptr;
780  curr = itor.curr;
781  curr_pos = itor.curr_pos;
782 
783  return *this;
784  }
785 
787  void reset_first() noexcept
788  {
789  curr = nullptr;
790  curr_pos = is_container_empty() ? Pos_Empty_Container : 0;
791  }
792 
794  void reset_last() noexcept
795  {
796  curr = nullptr;
797  curr_pos = (is_container_empty() ? Pos_Empty_Container :
798  COUNT(tree_ptr->getRoot()) - 1);
799  }
800 
802  void end() noexcept
803  {
804  put_itor_at_the_end(*this);
805  }
806 
814  void reset_to_key(const Key & key) noexcept
815  {
816  std::pair<int, Node*> p = tree_ptr->find_position(key);
817  curr_pos = p.first;
818  }
819 
825  void reset_to_node(Node * node) noexcept
826  {
827  curr = node;
828  curr_pos = -2;
829  }
830 
832  void reset_to_pos(size_t pos) noexcept
833  {
834  curr = nullptr;
835  curr_pos = pos;
836  }
837 
839  Node * get_curr_ne() const noexcept
840  {
841  if (not curr_updated())
842  update_curr();
843 
844  return curr;
845  }
846 
848  Node * get_curr() const noexcept
849  {
850  return get_curr_ne();
851  }
852 
861  size_t get_current_position() const
862  {
863  if (not pos_updated())
864  update_pos();
865 
866  if (curr_pos < -1 )
867  throw std::range_error("TreapRk iterator has not current");
868 
869  if (curr_pos > COUNT(tree_ptr->getRoot() ) )
870  throw std::range_error("TreapRk iterator has not current");
871 
872  return curr_pos;
873  }
874 
876  size_t get_pos() const { return get_current_position(); }
877 
879  bool has_curr() const noexcept
880  {
881  if (not pos_updated())
882  update_pos();
883 
884  return curr_pos >= 0 and curr_pos < COUNT(tree_ptr->getRoot());
885  }
886 
889  void prev()
890  {
891  if (not has_curr() )
892  throw std::underflow_error("TreapRk iterator has not current");
893 
894  --curr_pos;
895  curr = nullptr;
896  }
897 
898  void next_ne() noexcept
899  {
900  ++curr_pos;
901  curr = nullptr;
902  }
903 
906  void next()
907  {
908  if (not has_curr())
909  throw std::underflow_error("TreapRk iterator has not current");
910  next_ne();
911  }
912 
914  Node * del()
915  {
916  if (not has_curr())
917  throw std::underflow_error("TreapRk iterator has not current");
918 
919  if (not curr_updated())
920  update_curr();
921 
922  Node * ret_val = tree_ptr->remove(KEY(curr) );
923 
924  curr = nullptr;
925 
926  return ret_val;
927  }
928 
930  bool operator == (const Iterator & itor) const noexcept
931  {
932  if (is_container_empty() and itor.is_container_empty())
933  return true;
934 
935  if (pos_updated() and itor.pos_updated())
936  return curr_pos == itor.curr_pos;
937 
938  if (curr_updated() and itor.curr_updated())
939  return curr == itor.curr;
940 
941  if (not pos_updated())
942  {
943  update_pos();
944  return curr_pos == itor.curr_pos;
945  }
946 
947  itor.update_pos();
948 
949  return curr_pos == itor.curr_pos;
950  }
951 
953  bool operator != (const Iterator & itor) const
954  {
955  return not (*this == itor);
956  }
957 
958  bool verify(Gen_Treap_Rk * r) const noexcept
959  {
960  return tree_ptr->getRoot() == r->getRoot();
961  }
962 
963  bool verify(const Iterator & it) const noexcept
964  {
965  return tree_ptr->getRoot() == it.tree_ptr->getRoot();
966  }
967  }; // end class Iterator
968 };
969 
1009  template <typename Key, class Compare = Aleph::less<Key>>
1010 struct Treap_Rk : public Gen_Treap_Rk<Treap_Rk_Node, Key, Compare>
1011 {
1013  using Base::Base;
1014 };
1015 
1055  template <typename Key, class Compare = Aleph::less<Key>>
1056 struct Treap_Rk_Vtl : public Gen_Treap_Rk<Treap_Rk_NodeVtl, Key, Compare>
1057 {
1059  using Base::Base;
1060 };
1061 
1062 
1063 } // end namespace Aleph
1064 
1065 # endif // TPL_TREAPRK_H
void split_pos(size_t pos, Gen_Treap_Rk &t1, Gen_Treap_Rk &t2)
Definition: tpl_treapRk.H:588
void reset_to_key(const Key &key) noexcept
Definition: tpl_treapRk.H:814
void reset_to_pos(size_t pos) noexcept
Put the current to the position pos.
Definition: tpl_treapRk.H:832
Node * rotate_to_left_xt(Node *p) noexcept
Definition: tpl_binNodeXt.H:935
void next()
Definition: tpl_treapRk.H:906
Node * select(const size_t i) const
Definition: tpl_treapRk.H:487
Definition: tpl_treapRk.H:107
void split_key_dup(const Key &key, Gen_Treap_Rk &t1, Gen_Treap_Rk &t2) noexcept
Definition: tpl_treapRk.H:577
bool has_curr() const noexcept
Return true if iterator has current node.
Definition: tpl_treapRk.H:879
Iterator(const Gen_Treap_Rk &__tree) noexcept
Initialize an iterator on __tree
Definition: tpl_treapRk.H:746
auto & COUNT(Node *p) noexcept
Definition: tpl_binNodeXt.H:66
void reset_to_node(Node *node) noexcept
Definition: tpl_treapRk.H:825
long find_position(Node *r, const typename Node::key_type &key, Node *&p, Compare &cmp) noexcept
Definition: tpl_binNodeXt.H:290
std::pair< int, Node * > position(const Key &key) const noexcept
Definition: tpl_treapRk.H:507
void split_key_dup_rec_xt(Node *&root, const typename Node::key_type &key, Node *&l, Node *&r, Compare &cmp) noexcept
Definition: tpl_binNodeXt.H:572
Node * del()
Remove the current node and move the iterator one position forward.
Definition: tpl_treapRk.H:914
size_t get_current_position() const
Definition: tpl_treapRk.H:861
Node * remove_pos(const size_t pos)
Definition: tpl_treapRk.H:472
Node * search(const Key &key) const noexcept
Definition: tpl_treapRk.H:181
Node * insert(Node *p) noexcept
Definition: tpl_treapRk.H:301
Node * insert_dup(Node *p) noexcept
Definition: tpl_treapRk.H:317
bool verify() const
Return true if the treap is consistent.
Definition: tpl_treapRk.H:349
void join(Gen_Treap_Rk &t, Gen_Treap_Rk &dup) noexcept
Definition: tpl_treapRk.H:641
Node * rotate_to_right_xt(Node *p) noexcept
Definition: tpl_binNodeXt.H:914
Compare & key_comp() noexcept
return the comparison criteria
Definition: tpl_treapRk.H:138
std::pair< int, Node * > find_position(const Key &key) const noexcept
Definition: tpl_treapRk.H:543
Definition: tpl_binTreeOps.H:560
Definition: tpl_treapRk.H:684
Node * searchInBinTree(Node *root, const typename Node::key_type &key, Compare cmp=Compare()) noexcept
Definition: tpl_binNodeUtils.H:1323
Node::Key_Type & KEY(Node *p) noexcept
Definition: tpl_binNode.H:318
void split_pos_rec(Node *&r, const size_t i, Node *&ts, Node *&tg)
Definition: tpl_binNodeXt.H:710
Node * select(Node *r, const size_t pos)
Definition: tpl_binNodeXt.H:150
void join_dup(Gen_Treap_Rk &t) noexcept
Definition: tpl_treapRk.H:655
Definition: ah-comb.H:35
Iterator(const Gen_Treap_Rk &__tree, Node *__curr) noexcept
Initialize an iterator startin from node __curr
Definition: tpl_treapRk.H:753
void swap(Gen_Treap_Rk &tree) noexcept
Swap in constant time all the nodes of this with tree
Definition: tpl_treapRk.H:163
size_t get_pos() const
Definition: tpl_treapRk.H:876
long inorder_position(Node *r, const typename Node::key_type &key, Node *&p, Compare &cmp) noexcept
Definition: tpl_binNodeXt.H:210
Node *& LLINK(Node *p) noexcept
Definition: tpl_binNode.H:298
Node * get_curr_ne() const noexcept
Return the current node.
Definition: tpl_treapRk.H:839
void reset_last() noexcept
Reset the iterator to the last position.
Definition: tpl_treapRk.H:794
bool is_empty() const noexcept
Return true if tree is empty.
Definition: tpl_treapRk.H:496
Definition: tpl_treapRk.H:1010
Node * join(Node *t1, Node *t2, Node *&dup, Compare cmp=Compare()) noexcept
Definition: tpl_binNodeUtils.H:1855
Compare & get_compare() noexcept
Definition: tpl_treapRk.H:141
#define DECLARE_BINNODE_SENTINEL(Name, height, Control_Data)
Definition: tpl_binNode.H:272
unsigned long & PRIO(Node *p) noexcept
Definition: treapNode.H:63
size_t size() const noexcept
Return the number of nodes contained in the tree.
Definition: tpl_treapRk.H:493
Node *& getRoot() noexcept
Return the tree&#39;s root.
Definition: tpl_treapRk.H:171
bool split_key_rec_xt(Node *&root, const typename Node::key_type &key, Node *&l, Node *&r, Compare &cmp) noexcept
Definition: tpl_binNodeXt.H:512
Node * join_exclusive(Node *&ts, Node *&tg) noexcept
Definition: tpl_binNodeUtils.H:1708
void join_exclusive(Gen_Treap_Rk &t) noexcept
Definition: tpl_treapRk.H:672
Definition: tpl_treapRk.H:1056
Gen_Treap_Rk(unsigned long seed, Compare __cmp=Compare())
Definition: tpl_treapRk.H:145
Node * get_curr() const noexcept
Definition: tpl_treapRk.H:848
Node *& RLINK(Node *p) noexcept
Definition: tpl_binNode.H:307
void reset_first() noexcept
Reset the iterator to the first position.
Definition: tpl_treapRk.H:787
void prev()
Definition: tpl_treapRk.H:889
void end() noexcept
Put the iterator in the end state.
Definition: tpl_treapRk.H:802
Iterator(const Gen_Treap_Rk &__tree, const size_t pos) noexcept
Initialize an iterator starting from the iorder position pos
Definition: tpl_treapRk.H:761
Node * search_or_insert(Node *p) noexcept
Definition: tpl_treapRk.H:339
bool split_key(const Key &key, Gen_Treap_Rk &t1, Gen_Treap_Rk &t2) noexcept
Definition: tpl_treapRk.H:561
void set_seed(unsigned long seed) noexcept
Set the random number generator seed.
Definition: tpl_treapRk.H:135

Leandro Rabindranath León