DeSiGNAR  0.5a
Data Structures General Library
heap.H
Go to the documentation of this file.
1 /*
2  This file is part of Designar.
3  Copyright (C) 2017 by Alejandro J. Mujica
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  Any user request of this software, write to
19 
20  Alejandro Mujica
21 
22  aledrums@gmail.com
23 */
24 
25 # ifndef DSGHEAP_H
26 # define DSGHEAP_H
27 
28 # include <array.H>
29 # include <queue.H>
30 # include <nodesdef.H>
31 # include <sort.H>
32 
33 namespace Designar
34 {
35 
36  template <typename Key, class Cmp = std::less<Key>, nat_t cap = 100>
37  class FixedHeap
38  {
39  nat_t num_items;
40  Key array[cap];
41  Cmp & cmp;
42 
43  void copy(const FixedHeap &);
44 
45  void swap(FixedHeap & h)
46  {
47  std::swap(num_items, h.num_items);
48  std::swap(array, h.array);
49  std::swap(cmp, h.cmp);
50  }
51 
52  public:
53  using ItemType = Key;
54  using KeyType = Key;
55  using DataType = Key;
56  using ValueType = Key;
57  using SizeType = nat_t;
58  using CmpType = Cmp;
59 
60  FixedHeap(Cmp & _cmp)
61  : num_items(0), cmp(_cmp)
62  {
63  // empty
64  }
65 
66  FixedHeap(Cmp && _cmp = Cmp())
67  : FixedHeap(_cmp)
68  {
69  // empty
70  }
71 
72  FixedHeap(const FixedHeap & h)
73  : num_items(h.num_items), cmp(h.cmp)
74  {
75  copy(h);
76  }
77 
79  : FixedHeap()
80  {
81  swap(h);
82  }
83 
85  {
86  if (this == &h)
87  return *this;
88 
89  num_items = h.num_items;
90  cmp = h.cmp;
91  copy(h);
92  return *this;
93  }
94 
96  {
97  swap(h);
98  return *this;
99  }
100 
101  Cmp & get_cmp()
102  {
103  return cmp;
104  }
105 
106  const Cmp & get_cmp() const
107  {
108  return cmp;
109  }
110 
111  void clear()
112  {
113  num_items = 0;
114  }
115 
116  bool is_empty() const
117  {
118  return num_items == 0;
119  }
120 
121  bool is_full() const
122  {
123  return num_items == cap;
124  }
125 
126  nat_t size() const
127  {
128  return num_items;
129  }
130 
132  {
133  return cap;
134  }
135 
136  void insert(const Key & item)
137  {
138  if (is_full())
139  throw std::overflow_error("Heap is full");
140 
141  array[num_items] = item;
142  ++num_items;
143  sift_up(array - 1, 1, num_items, cmp);
144  }
145 
146  void insert(Key && item)
147  {
148  if (is_full())
149  throw std::overflow_error("Heap is full");
150 
151  array[num_items] = std::move(item);
152  ++num_items;
153  sift_up(array - 1, 1, num_items, cmp);
154  }
155 
156  const Key & top() const
157  {
158  if (is_empty())
159  throw std::underflow_error("Heap is empty");
160 
161  return array[0];
162  }
163 
164  Key get()
165  {
166  if (is_empty())
167  throw std::underflow_error("Heap is empty");
168 
169  Key ret_val = std::move(array[0]);
170  array[0] = std::move(array[num_items - 1]);
171  --num_items;
172  sift_down(array - 1, 1, num_items, cmp);
173  return ret_val;
174  }
175  };
176 
177  template <typename Key, class Cmp, nat_t cap>
179  {
180  for (nat_t i = 1; i <= cap; ++i)
181  array[i] = h.array[i];
182  }
183 
184  template <typename Key, class Cmp = std::less<Key>>
185  class DynHeap : private DynArray<Key>
186  {
187  using BaseArray = DynArray<Key>;
188 
189  static void sift_up(BaseArray &, nat_t, nat_t, Cmp &);
190 
191  static void sift_down(BaseArray &, nat_t, nat_t, Cmp &);
192 
193  Cmp & cmp;
194 
195  void swap(DynHeap & h)
196  {
197  BaseArray::swap(h);
198  std::swap(cmp, h.cmp);
199  }
200 
201  public:
202  using ItemType = Key;
203  using KeyType = Key;
204  using DataType = Key;
205  using ValueType = Key;
206  using SizeType = nat_t;
207  using CmpType = Cmp;
208 
209  DynHeap(Cmp & _cmp)
210  : BaseArray(), cmp(_cmp)
211  {
212  // empty
213  }
214 
215  DynHeap(Cmp && _cmp = Cmp())
216  : DynHeap(_cmp)
217  {
218  // empty
219  }
220 
221  DynHeap(const DynHeap & h)
222  : BaseArray(h), cmp(h.cmp)
223  {
224  // empty
225  }
226 
228  : DynHeap()
229  {
230  swap(h);
231  }
232 
234  {
235  if (this == &h)
236  return *this;
237 
238  (BaseArray &) *this = h;
239  cmp = h.cmp;
240  return *this;
241  }
242 
244  {
245  swap(h);
246  return *this;
247  }
248 
249  Cmp & get_cmp()
250  {
251  return cmp;
252  }
253 
254  const Cmp & get_cmp() const
255  {
256  return cmp;
257  }
258 
259  void clear()
260  {
261  BaseArray::clear();
262  }
263 
264  bool is_empty() const
265  {
266  return BaseArray::is_empty();
267  }
268 
269  nat_t size() const
270  {
271  return BaseArray::size();
272  }
273 
274  void insert(const Key & item)
275  {
276  BaseArray::append(item);
277  sift_up(*this, 1, size(), cmp);
278  }
279 
280  void insert(Key && item)
281  {
282  BaseArray::append(std::forward<Key>(item));
283  sift_up(*this, 1, size(), cmp);
284  }
285 
286  const Key & top() const
287  {
288  if (is_empty())
289  throw std::underflow_error("Heap is empty");
290 
291  return BaseArray::get_first();
292  }
293 
294  Key get()
295  {
296  if (is_empty())
297  throw std::underflow_error("Heap is empty");
298 
299  Key ret_val = std::move((*this)[0]);
300  (*this)[0] = std::move(BaseArray::get_last());
301  BaseArray::remove_last();
302  sift_down(*this, 1, size(), cmp);
303  return ret_val;
304  }
305  };
306 
307  template <typename Key, class Cmp>
308  void DynHeap<Key, Cmp>::sift_up(BaseArray & a, nat_t l, nat_t r, Cmp & cmp)
309  {
310  nat_t i = r;
311 
312  nat_t u = i / 2;
313 
314  while (u >= l and cmp(a[i - 1], a[u - 1]))
315  {
316  std::swap(a[i - 1], a[u - 1]);
317  i = u;
318  u = i / 2;
319  }
320  }
321 
322  template <typename Key, class Cmp>
323  void DynHeap<Key, Cmp>::sift_down(BaseArray & a, nat_t l, nat_t r, Cmp & cmp)
324  {
325  nat_t i = l;
326 
327  nat_t c = i * 2;
328 
329  while (c <= r)
330  {
331  if (c < r)
332  if (cmp(a[c], a[c - 1]))
333  ++c;
334 
335  if (not cmp(a[c - 1], a[i - 1]))
336  break;
337 
338  std::swap(a[c - 1], a[i - 1]);
339  i = c;
340  c = i * 2;
341  }
342  }
343 
344  template <typename Key>
345  class HeapNode :
346  public BaseBinTreeNode<Key, HeapNode<Key>, BinTreeNodeNullValue::NULLPTR>
347  {
348  using BaseNode =
350 
351  struct HeapNodeBits
352  {
353  unsigned int is_left : 4;
354  unsigned int is_leaf : 4;
355 
356  HeapNodeBits()
357  : is_left(true), is_leaf(true)
358  {
359  // empty
360  }
361  };
362 
363  HeapNode * parent = nullptr;
364  HeapNodeBits bits;
365 
366  public:
368  : BaseNode()
369  {
370  // empty
371  }
372 
373  HeapNode(const Key & k)
374  : BaseNode(k)
375  {
376  // empty
377  }
378 
379  HeapNode(Key && k)
380  : BaseNode(std::forward<Key>(k))
381  {
382  // empty
383  }
384 
386  : BaseNode(ctor)
387  {
388  // empty
389  }
390 
392  {
393  return parent;
394  }
395 
396  HeapNodeBits & get_bits()
397  {
398  return bits;
399  }
400 
401  unsigned int is_leaf() const
402  {
403  return bits.is_leaf;
404  }
405 
406  void set_leaf(unsigned int value)
407  {
408  bits.is_leaf = value;
409  }
410 
411  unsigned int is_left() const
412  {
413  return bits.is_left;
414  }
415 
416  void set_left(unsigned int value)
417  {
418  bits.is_left = value;
419  }
420 
421  void reset()
422  {
423  bits.is_leaf = true;
424  bits.is_left = true;
425  }
426  };
427 
428  template <class HeapNode>
429  inline HeapNode *& U(HeapNode * p)
430  {
431  return p->get_parent();
432  }
433 
434  template <typename Key, class Cmp = std::less<Key>>
435  class LHeap
436  {
437  using Node = HeapNode<Key>;
438 
439  static Node * key_to_node(Key & k)
440  {
441  Node * node_zero = 0;
442  size_t offset = (size_t) &(KEY(node_zero));
443  unsigned long addr = (unsigned long)(&k);
444  return (Node*) (addr - offset);
445  }
446 
447  static bool is_in_list(Node * p)
448  {
449  if (p->is_leaf())
450  return true;
451 
452  return U(L(p)) == R(L(p));
453  }
454 
455  static bool has_sibling(Node * p)
456  {
457  return U(p) != R(p);
458  }
459 
460  static void destroy_rec(Node *, Node *);
461 
462  void swap_with_parent(Node * p)
463  {
464  assert(num_items >= 2);
465  assert(p != root);
466 
467  Node * pp = U(p);
468 
469  const bool p_has_sibling = has_sibling(p);
470  const bool p_is_in_list = is_in_list(p);
471  const bool pp_is_in_list = is_in_list(pp);
472  const bool p_has_child = not p->is_leaf();
473 
474  std::swap(pp->get_bits(), p->get_bits());
475 
476  if (pp == root)
477  root = p;
478 
479  Node * ppp = U(pp);
480 
481  U(pp) = p;
482  U(p) = ppp;
483 
484  if (L(ppp) == pp)
485  L(ppp) = p;
486  else
487  R(ppp) = p;
488 
489  Node * sp = nullptr;
490 
491  if (p_has_sibling)
492  {
493  sp = p == L(pp) ? R(pp) : L(pp);
494  assert(U(sp) == pp);
495  U(sp) = p;
496  }
497 
498  if (p == last)
499  last = pp;
500 
501  if (num_items == 2)
502  return;
503 
504  Node * lcp = L(p);
505  Node * rcp = R(p);
506 
507  if (num_items == 3)
508  {
509  if (R(pp) == p)
510  {
511  L(lcp) = R(lcp) = pp;
512  R(pp) = lcp;
513  R(p) = pp;
514  }
515  else
516  {
517  L(rcp) = R(rcp) = pp;
518  L(pp) = rcp;
519  L(p) = pp;
520  }
521 
522  return;
523  }
524 
525  if (not p_is_in_list)
526  {
527  U(lcp) = U(rcp) = pp;
528 
529  if (L(pp) == p)
530  {
531  assert(R(pp) == sp);
532  L(p) = pp;
533  R(p) = R(pp);
534  }
535  else
536  {
537  assert(L(pp) == sp);
538  R(p) = pp;
539  L(p) = L(pp);
540  }
541 
542  L(pp) = lcp;
543  R(pp) = rcp;
544 
545  return;
546  }
547 
548  if (not pp_is_in_list)
549  {
550  if (p_has_child)
551  U(L(p)) = pp;
552 
553  R(lcp) = L(rcp) = pp;
554 
555  if (L(pp) == p)
556  {
557  assert(R(pp) == sp);
558  L(p) = pp;
559  R(p) = R(pp);
560  }
561  else
562  {
563  assert(L(pp) == sp);
564  R(p) = pp;
565  L(p) = L(pp);
566  }
567 
568  L(pp) = lcp;
569  R(pp) = rcp;
570 
571  return;
572  }
573 
574  R(lcp) = pp;
575  L(R(pp)) = p;
576  L(pp) = lcp;
577  R(p) = R(pp);
578  R(pp) = p;
579  L(p) = pp;
580  }
581 
582  void swap_last_with_root()
583  {
584  assert(num_items > 1);
585  assert(U(root) == head);
586  assert(not root->is_leaf());
587  assert(last->is_leaf());
588 
589  if (num_items > 3)
590  {
591  Node * lRoot = L(root);
592  Node * rRoot = R(root);
593  Node * f_last = U(last);
594  Node * prev_last = L(last);
595  Node * next_last = R(last);
596 
597  if (L(f_last) == last)
598  L(f_last) = root;
599  else
600  R(f_last) = root;
601 
602  if (R(root) != last)
603  std::swap(U(root), U(last));
604  else
605  {
606  U(root) = last;
607  U(root) = head;
608  }
609 
610  std::swap(L(root), L(last));
611  std::swap(R(root), R(last));
612 
613  U(lRoot) = U(rRoot) = last;
614 
615  L(last) = lRoot;
616  R(last) = rRoot;
617 
618  L(root) = prev_last;
619  R(root) = next_last;
620 
621  R(prev_last) = L(next_last) = root;
622  }
623  else if (num_items == 3)
624  {
625  assert(R(root) == last);
626  assert(L(last) == L(root) and R(last) == L(root));
627 
628  U(last) = U(root);
629  U(root) = last;
630 
631  Node *s_last = L(last);
632  U(s_last) = last;
633 
634  L(last) = s_last;
635  R(last) = root;
636 
637  L(root) = R(root) = s_last;
638  R(s_last) = L(s_last) = root;
639  }
640  else
641  {
642  assert(L(root) == last);
643 
644  U(last) = U(root);
645  U(root) = last;
646  R(last) = L(last) = root;
647  R(root) = L(root) = last;
648  }
649 
650  std::swap(root->get_bits(), last->get_bits());
651  std::swap(root, last);
652  }
653 
654  void replace_node(Node * node, Node * new_node)
655  {
656  assert(node != new_node);
657  assert(node != last);
658 
659  Node * parent = U(node);
660  Node * left_child = L(node);
661  Node * right_child = R(node);
662 
663  U(new_node) = parent;
664  L(new_node) = left_child;
665  R(new_node) = right_child;
666 
667  if (node->is_left())
668  {
669  assert(L(parent) == node);
670  L(parent) = new_node;
671  }
672  else
673  {
674  assert(R(parent) == node);
675  R(parent) = new_node;
676  }
677 
678  if (node->is_leaf())
679  {
680  R(left_child) = new_node;
681  L(right_child) = new_node;
682  }
683  else
684  {
685  U(left_child) = new_node;
686 
687  if (U(right_child) == node) // node pudiera tener sólo un hijo
688  U(right_child) = new_node;
689  else
690  {
691  assert(left_child == last);
692  R(left_child) = new_node;
693  L(right_child) = new_node;
694  }
695  }
696 
697  new_node->get_bits() = node->get_bits();
698  }
699 
700  Node * insert_node(Node * p)
701  {
702  assert(p->is_leaf());
703 
704  if (root == nullptr)
705  {
706  assert(num_items == 0);
707 
708  root = p;
709  L(p) = R(p) = p;
710  U(p) = head;
711  p->set_leaf(true);
712  p->set_left(false);
713  last = root;
714  num_items = 1;
715  return p;
716  }
717 
718  Node * pp = R(last);
719  L(p) = last;
720  U(p) = pp;
721 
722  if (last->is_left())
723  {
724  p->set_left(false);
725  R(p) = R(pp);
726  L(R(pp)) = p;
727  R(pp) = p;
728  }
729  else
730  {
731  p->set_left(true);
732  R(p) = pp;
733  pp->set_leaf(false);
734  L(pp) = p;
735  }
736 
737  assert(not pp->is_leaf());
738 
739  R(last) = p;
740  last = p;
741  ++num_items;
742  sift_up(last);
743  return p;
744  }
745 
746  Node * remove_top()
747  {
748  if (root == nullptr)
749  throw std::underflow_error("Heap is empty");
750 
751  Node * p = root;
752 
753  if (num_items == 1)
754  {
755  root = nullptr;
756  num_items = 0;
757  }
758  else
759  {
760  swap_last_with_root();
761  remove_last();
762  sift_down(root);
763  }
764 
765  p->reset();
766  return p;
767  }
768 
769  Node * remove_last()
770  {
771  assert(last != root and num_items > 0);
772  assert(last->is_leaf());
773 
774  Node * ret_val = last;
775  Node * pp = U(last);
776  Node * new_last = L(last);
777 
778  if (last->is_left())
779  {
780  pp->set_leaf(true);
781  L(pp) = new_last;
782  }
783  else
784  {
785  R(pp) = R(last);
786  L(R(last)) = pp;
787  }
788 
789  R(L(last)) = pp;
790  last = new_last;
791  --num_items;
792  ret_val->reset();
793 
794  return ret_val;
795  }
796 
797  Node * remove(Node * p)
798  {
799  if (root == nullptr)
800  throw std::underflow_error ("Heap is empty");
801 
802  if (p == root)
803  return remove_top();
804 
805  if (p == last)
806  return remove_last();
807 
808  Node * q = remove_last();
809 
810  if (p == last)
811  {
812  remove_last();
813  insert_node(q);
814 
815  return p;
816  }
817 
818  replace_node(p, q);
819  update(q);
820  p->reset();
821 
822  return p;
823  }
824 
825  void sift_up(Node *);
826 
827  void sift_down(Node *);
828 
829  void update(Node * p)
830  {
831  sift_down(p);
832  sift_up(p);
833  }
834 
835 
836  Node head_node;
837  Node * head;
838  Node *& root;
839  Node * last;
840  nat_t num_items;
841  Cmp & cmp;
842 
843  public:
844  using ItemType = Key;
845  using KeyType = Key;
846  using DataType = Key;
847  using ValueType = Key;
848  using SizeType = nat_t;
849  using CmpType = Cmp;
850 
851  LHeap(Cmp & _cmp)
852  : head(&head_node), root(R(head)), last(nullptr), num_items(0), cmp(_cmp)
853  {
854  // empty
855  }
856 
857  LHeap(Cmp && _cmp = Cmp())
858  : LHeap(_cmp)
859  {
860  // empty
861  }
862 
863  LHeap(LHeap && h)
864  : LHeap()
865  {
866  swap(h);
867  }
868 
870  {
871  clear();
872  }
873 
875  {
876  swap(h);
877  return *this;
878  }
879 
880  void swap(LHeap & h)
881  {
882  std::swap(root, h.root);
883  std::swap(last, h.last);
884  std::swap(num_items, h.num_items);
885  std::swap(cmp, h.cmp);
886  }
887 
888  Cmp & get_cmp()
889  {
890  return cmp;
891  }
892 
893  const Cmp & get_cmp() const
894  {
895  return cmp;
896  }
897 
898  void clear();
899 
900  nat_t size() const
901  {
902  return num_items;
903  }
904 
905  bool is_empty() const
906  {
907  return num_items == 0;
908  }
909 
910  const Key & insert(const Key & k)
911  {
912  Node * p = new Node(k);
913  return KEY(insert_node(p));
914  }
915 
916  const Key & insert(Key && k)
917  {
918  Node * p = new Node(std::forward<Key>(k));
919  return KEY(insert_node(p));
920  }
921 
922  const Key & top() const
923  {
924  if (is_empty())
925  throw std::underflow_error("Heap is empty");
926 
927  return KEY(root);
928  }
929 
930  Key get()
931  {
932  Node * p = remove_top();
933  Key ret_val = std::move(KEY(p));
934  delete p;
935  return ret_val;
936  }
937 
938  void remove(Key & item)
939  {
940  Node * p = remove(key_to_node(item));
941  delete p;
942  }
943  };
944 
945  template <typename Key, class Cmp>
946  void LHeap<Key, Cmp>::destroy_rec(Node * p, Node * n)
947  {
948  if (p->is_leaf())
949  {
950  delete p;
951  return;
952  }
953 
954  destroy_rec(L(p), n);
955 
956  if (p != n)
957  destroy_rec(R(p), n);
958 
959  delete p;
960  }
961 
962  template <typename Key, class Cmp>
964  {
965  while (p != root and cmp(KEY(p), KEY(U(p))))
966  swap_with_parent(p);
967  }
968 
969  template <typename Key, class Cmp>
971  {
972  while (not p->is_leaf())
973  {
974  Node * c = L(p);
975 
976  if (has_sibling(c))
977  if (cmp(KEY(R(p)), KEY(L(p))))
978  c = R(p);
979 
980  if (not cmp(KEY(c), KEY(p)))
981  return;
982 
983  swap_with_parent(c);
984  }
985  }
986 
987  template <typename Key, class Cmp>
989  {
990  if (root == nullptr)
991  return;
992 
993  if (num_items <= 3)
994  {
995  while (not is_empty())
996  get();
997  return;
998  }
999 
1000  if (last->is_left())
1001  destroy_rec(root, U(last));
1002  else
1003  destroy_rec(root, nullptr);
1004 
1005  root = nullptr;
1006  last = head;
1007  num_items = 0;
1008  }
1009 
1010 } // end namespace Designar
1011 
1012 # endif // DSGHEAP_H
HeapNode(BinTreeNodeCtor ctor)
Definition: heap.H:385
nat_t size() const
Definition: heap.H:269
LHeap(LHeap &&h)
Definition: heap.H:863
LHeap(Cmp &&_cmp=Cmp())
Definition: heap.H:857
unsigned int is_leaf() const
Definition: heap.H:401
void insert(const Key &item)
Definition: heap.H:136
T DataType
Definition: array.H:194
HeapNode(Key &&k)
Definition: heap.H:379
Key ValueType
Definition: heap.H:56
nat_t size() const
Definition: heap.H:900
void clear()
Definition: heap.H:988
DynHeap(Cmp &_cmp)
Definition: heap.H:209
Cmp CmpType
Definition: heap.H:207
FixedHeap & operator=(const FixedHeap &h)
Definition: heap.H:84
const Key & top() const
Definition: heap.H:286
void insert(Key &&item)
Definition: heap.H:280
void set_leaf(unsigned int value)
Definition: heap.H:406
~LHeap()
Definition: heap.H:869
Key DataType
Definition: heap.H:55
HeapNode *& get_parent()
Definition: heap.H:391
void clear()
Definition: heap.H:259
const Cmp & get_cmp() const
Definition: heap.H:254
void reset()
Definition: heap.H:421
HeapNode *& U(HeapNode *p)
Definition: heap.H:429
Cmp & get_cmp()
Definition: heap.H:101
void insert(const Key &item)
Definition: heap.H:274
FixedHeap(Cmp &_cmp)
Definition: heap.H:60
bool is_empty() const
Definition: heap.H:116
bool is_full() const
Definition: heap.H:121
unsigned int is_left() const
Definition: heap.H:411
LHeap(Cmp &_cmp)
Definition: heap.H:851
Key ItemType
Definition: heap.H:53
BinTreeNode *& R(BinTreeNode *p)
Definition: nodesdef.H:993
Definition: nodesdef.H:902
FixedHeap(const FixedHeap &h)
Definition: heap.H:72
const Key & insert(const Key &k)
Definition: heap.H:910
Cmp & get_cmp()
Definition: heap.H:888
const Cmp & get_cmp() const
Definition: heap.H:106
HeapNode(const Key &k)
Definition: heap.H:373
Cmp CmpType
Definition: heap.H:58
void insert(Key &&item)
Definition: heap.H:146
nat_t SizeType
Definition: heap.H:57
const Key & insert(Key &&k)
Definition: heap.H:916
nat_t size() const
Definition: heap.H:126
DynHeap(DynHeap &&h)
Definition: heap.H:227
Definition: array.H:375
T ItemType
Definition: array.H:192
bool is_empty() const
Definition: heap.H:264
typename GT::Node Node
Definition: graphutilities.H:78
void set_left(unsigned int value)
Definition: heap.H:416
BinTreeNode *& L(BinTreeNode *p)
Definition: nodesdef.H:987
Definition: heap.H:435
HeapNode()
Definition: heap.H:367
Key KeyType
Definition: heap.H:54
Cmp & get_cmp()
Definition: heap.H:249
void sift_up(T *, nat_t, nat_t, Cmp &)
Definition: sort.H:336
void clear()
Definition: heap.H:111
Definition: heap.H:185
const Cmp & get_cmp() const
Definition: heap.H:893
DynHeap(const DynHeap &h)
Definition: heap.H:221
nat_t SizeType
Definition: array.H:196
const Key & top() const
Definition: heap.H:922
FixedHeap(FixedHeap &&h)
Definition: heap.H:78
BinTreeNode::KeyType & KEY(BinTreeNode *p)
Definition: nodesdef.H:981
FixedHeap(Cmp &&_cmp=Cmp())
Definition: heap.H:66
BinTreeNodeCtor
Definition: nodesdef.H:897
Definition: array.H:32
T ValueType
Definition: array.H:195
void sift_down(T *, nat_t, nat_t, Cmp &)
Definition: sort.H:357
Definition: heap.H:345
bool is_empty() const
Definition: heap.H:905
unsigned long int nat_t
Definition: types.H:50
DynHeap(Cmp &&_cmp=Cmp())
Definition: heap.H:215
nat_t get_capacity() const
Definition: heap.H:131
Value & value(MapKey< Key, Value > &item)
Definition: map.H:77
Definition: graphalgorithms.H:1212
Definition: heap.H:37
void swap(LHeap &h)
Definition: heap.H:880
const Key & top() const
Definition: heap.H:156
HeapNodeBits & get_bits()
Definition: heap.H:396
T KeyType
Definition: array.H:193