Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
tpl_avl.H
Go to the documentation of this file.
1
2/*
3 Aleph_w
4
5 Data structures & Algorithms
6 version 2.0.0b
7 https://github.com/lrleon/Aleph-w
8
9 This file is part of Aleph-w library
10
11 Copyright (c) 2002-2026 Leandro Rabindranath Leon
12
13 Permission is hereby granted, free of charge, to any person obtaining a copy
14 of this software and associated documentation files (the "Software"), to deal
15 in the Software without restriction, including without limitation the rights
16 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
17 copies of the Software, and to permit persons to whom the Software is
18 furnished to do so, subject to the following conditions:
19
20 The above copyright notice and this permission notice shall be included in all
21 copies or substantial portions of the Software.
22
23 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
24 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
25 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
26 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
27 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
28 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
29 SOFTWARE.
30*/
31
50#ifndef TPL_AVL_H
51#define TPL_AVL_H
52
53#include <algorithm>
54#include <ahFunction.H>
55#include <tpl_arrayStack.H>
56#include <avlNode.H>
57#include <tpl_binNodeUtils.H>
58#include <ah-concepts.H>
59
60namespace Aleph {
102template <template <typename> class NodeType, typename Key, class Compare>
103 requires StrictWeakOrder<Compare, Key>
105{
106public:
107 using Node = NodeType<Key>;
108
109private:
113 Compare cmp;
114
115 /* The path from the head node to the node an operation works on. Each
116 operation builds it, consumes it and drops it: it lives in the frame
117 of the operation, so the tree never allocates. Its base is head_ptr. */
118 // The head node, then at most Node::MaxHeight nodes of the tree.
120
122 static bool at_head(const Path &path) noexcept
123 {
124 return path.size() == 1;
125 }
126
127 // The searches only read the tree: a comparison that throws leaves it as
128 // it was, and the operations that call them change it after them
129 Node *search_and_stack_avl(const Key &key, signed char &cmp_result, Path &path)
130 noexcept(nothrow_compare_v<Compare, Key>)
131 {
132 assert(at_head(path) and path.base() == head_ptr);
133
134 Node *p = root;
135 Node *candidate = nullptr; // Tracks potential duplicate when going right
136 size_t candidate_pos = 0; // Stack size when candidate was set
137
138 do // descend searching for key and push the search path
139 {
140 __builtin_prefetch(LLINK(p));
141 __builtin_prefetch(RLINK(p));
142 path.push(p);
143 if (cmp(key, KEY(p))) // key < KEY(p)
144 {
145 cmp_result = CmpLess;
146 p = LLINK(p);
147 }
148 else // key >= KEY(p), could be equal
149 {
150 candidate = p;
151 candidate_pos = path.size();
152 cmp_result = CmpGreater;
153 p = RLINK(p);
154 }
155 } while (p != Node::NullPtr);
156
157 // Optimistic duplicate check: when going right, key >= KEY(candidate)
158 // If also KEY(candidate) >= key (i.e., not less), then key == KEY(candidate)
159 if (candidate != nullptr and not static_cast<bool>(cmp(KEY(candidate), key))) [[unlikely]]
160 {
161 cmp_result = CmpEqual;
162 // Truncate stack: remove nodes pushed after candidate
163 const size_t to_pop = path.size() > candidate_pos ? path.size() - candidate_pos : 0;
164 if (to_pop > 0)
165 path.popn(to_pop);
166 return candidate;
167 }
168
169 return path.top();
170 }
171
172 Node *search_dup_and_stack_avl(const Key &key, signed char &cmp_result, Path &path)
173 noexcept(nothrow_compare_v<Compare, Key>)
174 {
175 assert(at_head(path) and path.base() == head_ptr);
176 cmp_result = CmpEqual;
177
178 Node *p = root;
179 do // descend searching for key and push the search path
180 {
181 __builtin_prefetch(LLINK(p));
182 __builtin_prefetch(RLINK(p));
183 path.push(p);
184 if (cmp(key, KEY(p))) // key < KEY(p)?
185 {
186 cmp_result = CmpLess;
187 p = LLINK(p);
188 }
189 else // key >= KEY(p)
190 {
191 cmp_result = CmpGreater;
192 p = RLINK(p);
193 }
194 } while (p != Node::NullPtr);
195
196 return path.top();
197 }
198
199 [[gnu::always_inline]] static Node *rotateLeft(Node *p) noexcept
200 {
201 assert(DIFF(p) == 2);
202 assert(RLINK(p) != Node::NullPtr);
203
204 Node *q = RLINK(p);
205 RLINK(p) = LLINK(q);
206 LLINK(q) = p;
207
208 if (DIFF(q) == 0) // balance factors adjustment
209 { // this case happens during deletion
210 DIFF(q) = -1;
211 DIFF(p) = 1;
212 }
213 else
214 DIFF(q) = DIFF(p) = 0;
215
216 return q;
217 }
218
219 [[gnu::always_inline]] static Node *rotateRight(Node *p) noexcept
220 {
221 assert(DIFF(p) == -2);
222 assert(LLINK(p) != Node::NullPtr);
223
224 Node *q = LLINK(p);
225 LLINK(p) = RLINK(q);
226 RLINK(q) = p;
227
228 if (DIFF(q) == 0) // balance factors adjustment
229 { // this case happens during deletion
230 DIFF(q) = 1;
231 DIFF(p) = -1;
232 }
233 else
234 DIFF(q) = DIFF(p) = 0;
235
236 return q;
237 }
238
239 [[gnu::always_inline]] static Node *doubleRotateLeft(Node *p) noexcept
240 {
241 assert(DIFF(p) == 2 or DIFF(p) == -2);
242 assert(RLINK(p) != Node::NullPtr and LLINK(RLINK(p)) != Node::NullPtr);
243
244 Node *q = RLINK(p);
245 Node *r = LLINK(q);
246 RLINK(p) = LLINK(r);
247 LLINK(q) = RLINK(r);
248 LLINK(r) = p;
249 RLINK(r) = q;
250
251 unsigned char b; // logical height of r's left child
252 unsigned char c; // logical height of r's right child
253
254 // Determine logical heights of p, q and r
255 if (DIFF(r) == 1) // ==> c > b ==> c-b == 1
256 {
257 c = 1;
258 b = 0;
259 }
260 else if (DIFF(r) == -1) // ==> c < b ==> c-b = -1
261 {
262 c = 0;
263 b = 1;
264 }
265 else
266 c = b = 1;
267
268 // balance factors adjustment
269 DIFF(r) = 0;
270 DIFF(p) = b - 1; // logical height of p's left child is 1
271 DIFF(q) = 1 - c; // logical height of q's right child is 1
272
273 return r;
274 }
275
276 [[gnu::always_inline]] static Node *doubleRotateRight(Node *p) noexcept
277 {
278 assert(DIFF(p) == 2 or DIFF(p) == -2);
279 assert(LLINK(p) != Node::NullPtr and RLINK(LLINK(p)) != Node::NullPtr);
280
281 Node *q = LLINK(p);
282 Node *r = RLINK(q);
283 LLINK(p) = RLINK(r);
284 RLINK(q) = LLINK(r);
285 RLINK(r) = p;
286 LLINK(r) = q;
287
288 unsigned char b; // logical height of r's left child
289 unsigned char c; // logical height of r's right child
290
291 // determine logical heights of children of p, q and r
292 if (DIFF(r) == 1) // ==> c > b ==> c-b == 1
293 {
294 c = 1;
295 b = 0;
296 }
297 else if (DIFF(r) == -1) // ==> c < b ==> c-b == -1
298 {
299 c = 0;
300 b = 1;
301 }
302 else
303 c = b = 1;
304
305 // balance factors adjustment
306 DIFF(r) = 0;
307 DIFF(p) = 1 - c; // logical height of p's right child is 1
308 DIFF(q) = b - 1; // logical height of p's left child is 1
309
310 return r;
311 }
312
320
321 static Rotation_Type rotation_type(Node *p) noexcept
322 {
323 assert(DIFF(p) == 2 or DIFF(p) == -2);
324
325 Node *pc; // saves p's child
326 if (DIFF(p) == 2) // to the left
327 {
328 pc = RLINK(p);
329 if (DIFF(pc) == 1 or DIFF(pc) == 0)
330 return ROTATE_LEFT;
331
332 return DOUBLE_ROTATE_LEFT;
333 }
334
335 pc = LLINK(p);
336 if (DIFF(pc) == -1 or DIFF(pc) == 0)
337 return ROTATE_RIGHT;
338
339 return DOUBLE_ROTATE_RIGHT;
340 }
341
342 static Node *restore_avl(Node *p, Node *pp) noexcept
343 {
344 assert(LLINK(pp) == p or RLINK(pp) == p);
345 assert(DIFF(p) == -2 or DIFF(p) == 2);
346
347 Node **link = LLINK(pp) == p ? &LLINK(pp) : &RLINK(pp);
348 switch (rotation_type(p))
349 {
350 case ROTATE_LEFT:
351 return *link = rotateLeft(p);
352 case ROTATE_RIGHT:
353 return *link = rotateRight(p);
355 return *link = doubleRotateLeft(p);
357 return *link = doubleRotateRight(p);
358
359 default:
360 AH_ERROR("Invalid rotation type");
361 break;
362 }
363
364 return nullptr;
365 }
366
367 void restore_avl_after_insertion(Node *p, Path &path) noexcept
368 {
369 Node *pp = path.pop(); // parent of the inserted node
370 if (LLINK(pp) == p) // adjust parent's balance factor
371 --DIFF(pp);
372 else
373 ++DIFF(pp);
374
375 if (DIFF(pp) == 0) // in this case, the height of pp's ancestor does not increase
376 return;
377
378 if (at_head(path))
379 return; // pp is the root
380 do // search a node whose balance factor becomes 0
381 {
382 Node *gpp = path.pop(); // parent of pp
383 // update balance factors
384 if (LLINK(gpp) == pp) // AH_ERROR if (Compare () (key, KEY(gpp)))
385 --DIFF(gpp);
386 else
387 ++DIFF(gpp);
388
389 if (DIFF(gpp) == 0)
390 break; // no rebalancing is needed
391 if (DIFF(gpp) == -2 or DIFF(gpp) == 2) // AVL violation?
392 { // yes ==> rebalancing is required
393 Node *ggpp = path.pop();
394 restore_avl(gpp, ggpp);
395 break;
396 }
397
398 pp = gpp; // AH_ERROR; add
399 } while (not at_head(path));
400 }
401
402 Node *swapWithSuccessor(Node *p, Node *&pp, Path &path) noexcept
403 { // Reference to the stack top, since p will be swapped with its
404 // successor and the successor will take p's position in the stack
405 Node *&ref_to_stack_top = path.top();
406
407 Node *fSucc = p; // successor's parent
408 Node *succ = RLINK(p); // search starts from RLINK(p)
409
410 path.push(succ);
411
412 // find the successor while updating the stack
413 while (LLINK(succ) != Node::NullPtr) // descend as far left as possible
414 {
415 fSucc = succ;
416 succ = LLINK(succ);
417 path.push(succ);
418 }
419
420 // update old stack entry occupied by p: it is equivalent to swapping
421 // the old top (before searching succ) with the current one
422 ref_to_stack_top = succ;
423 path.top() = p;
424 if (LLINK(pp) == p) // update pp's new child (successor)
425 LLINK(pp) = succ;
426 else
427 RLINK(pp) = succ;
428
429 LLINK(succ) = LLINK(p); // swap left subtrees
430 LLINK(p) = Node::NullPtr;
431 if (RLINK(p) == succ) // update right subtrees
432 { // successor is exactly p's right child
433 RLINK(p) = RLINK(succ);
434 RLINK(succ) = p;
435 pp = succ;
436 }
437 else
438 { // successor is the leftmost descendant of RLINK(p)
439 Node *succr = RLINK(succ);
440 RLINK(succ) = RLINK(p);
441 LLINK(fSucc) = p;
442 RLINK(p) = succr;
443 pp = fSucc;
444 }
445
446 DIFF(succ) = DIFF(p); // swap balance factors
447
448 return succ;
449 }
450
451 void restore_avl_after_deletion(bool left_deficit, Path &path) noexcept
452 {
453 Node *pp = path.top(1); // parent of p
454 Node *ppp = path.popn(3); // remove from stack p, parent and grandparent
455 while (true)
456 { // update balance factors
457 if (left_deficit) // AH_ERROR Compare () (key, KEY(pp)))
458 ++DIFF(pp);
459 else
460 --DIFF(pp);
461
462 if (DIFF(pp) == -2 or DIFF(pp) == 2) // still valid?
463 pp = restore_avl(pp, ppp); // no
464
465 if (DIFF(pp) != 0 or pp == root)
466 break; // global tree height has not changed ==> stop
467
468 left_deficit = LLINK(ppp) == pp;
469 pp = ppp; // advance to next ancestor
470 ppp = path.pop();
471 }
472 }
473
474public:
475 using key_type = Key;
476
478 [[nodiscard]] constexpr Compare &key_comp() noexcept
479 {
480 return cmp;
481 }
482
484 [[nodiscard]] constexpr Compare &get_compare() noexcept
485 {
486 return key_comp();
487 }
488
503 noexcept(std::is_nothrow_default_constructible_v<Node> and
504 std::is_nothrow_default_constructible_v<Compare> and
505 std::is_nothrow_constructible_v<Compare, Compare &>)
506 : Gen_Avl_Tree(Compare())
507 {
508 // empty
509 }
510
519 Gen_Avl_Tree(Compare _cmp)
520 noexcept(std::is_nothrow_default_constructible_v<Node> and
521 std::is_nothrow_constructible_v<Compare, Compare &>)
523 {
524 // empty
525 }
526
535 Gen_Avl_Tree(const Gen_Avl_Tree &) = delete;
536
539
558 noexcept(bin_node_detail::nothrow_header_from_v<Node> and
559 bin_node_detail::nothrow_compare_taken_v<Compare>)
560 : head_node(bin_node_detail::header_from(tree.head_node)),
562 cmp(bin_node_detail::compare_to_take(tree.cmp))
563 {
564 root = tree.root;
565 tree.root = Node::NullPtr;
566 }
567
575 void swap(Gen_Avl_Tree &tree) noexcept(std::is_nothrow_swappable_v<Compare>)
576 {
577 // The comparison first: if its swap throws, the nodes stay where
578 // they were
579 std::swap(cmp, tree.cmp);
580 std::swap(root, tree.root);
581 }
582
583 virtual ~Gen_Avl_Tree() noexcept = default;
584
586 [[nodiscard]] constexpr Node *&getRoot() noexcept
587 {
588 return root;
589 }
590
592 [[nodiscard]] constexpr Node *getRoot() const noexcept
593 {
594 return root;
595 }
596
607 [[nodiscard]] Node *search(const Key &key) const
608 noexcept(nothrow_compare_v<Compare, Key>)
609 {
610 Node *p = root;
611 while (p != Node::NullPtr)
612 {
613 __builtin_prefetch(LLINK(p));
614 __builtin_prefetch(RLINK(p));
615 if (cmp(key, KEY(p)))
616 p = LLINK(p);
617 else if (cmp(KEY(p), key))
618 p = RLINK(p);
619 else
620 return p;
621 }
622 return nullptr;
623 }
624
640 [[nodiscard]] Node *insert(Node *p) noexcept(nothrow_compare_v<Compare, Key>)
641 {
642 if (root == Node::NullPtr)
643 return root = p;
644
645 signed char cmp_result = CmpEqual;
646 Path path;
647 path.push(head_ptr);
648 Node *pp = search_and_stack_avl(KEY(p), cmp_result, path);
649 if (cmp_result == CmpLess)
650 LLINK(pp) = p;
651 else if (cmp_result == CmpGreater)
652 RLINK(pp) = p;
653 else
654 return nullptr; // duplicated key
655
657
658 return p;
659 }
660
680 [[nodiscard]] Node *search_or_insert(Node *p) noexcept(nothrow_compare_v<Compare, Key>)
681 {
682 if (root == Node::NullPtr)
683 return root = p;
684
685 signed char cmp_result = CmpEqual;
686 Path path;
687 path.push(head_ptr);
688 Node *pp = search_and_stack_avl(KEY(p), cmp_result, path);
689 if (cmp_result == CmpLess)
690 LLINK(pp) = p;
691 else if (cmp_result == CmpGreater)
692 RLINK(pp) = p;
693 else
694 return pp; // duplicated key
695
697
698 return p;
699 }
700
710 [[nodiscard]] Node *insert_dup(Node *p) noexcept(nothrow_compare_v<Compare, Key>)
711 {
712 if (root == Node::NullPtr)
713 return root = p;
714
715 signed char cmp_result = CmpEqual;
716 Path path;
717 path.push(head_ptr);
718 Node *pp = search_dup_and_stack_avl(KEY(p), cmp_result, path);
719 if (cmp_result == CmpLess)
720 LLINK(pp) = p;
721 else
722 RLINK(pp) = p;
723
725
726 return p;
727 }
728
738 [[nodiscard]] Node *remove(const Key &key) noexcept(nothrow_compare_v<Compare, Key>)
739 {
740 if (root == Node::NullPtr)
741 return nullptr;
742
743 signed char cmp_result = CmpEqual;
744 Path path;
745 path.push(head_ptr);
746 Node *p = search_and_stack_avl(key, cmp_result, path);
747 if (cmp_result != CmpEqual)
748 return nullptr; // key was not found
749
750 Node *pp = path.top(1); // get parent of p
751 bool left_deficit; // AH_ERROR Key removed_key = KEY(p);
752 while (true)
753 {
754 left_deficit = LLINK(pp) == p;
755 if (LLINK(p) == Node::NullPtr) // missing left child?
756 { // yes: link pp to p's child
757 if (LLINK(pp) == p)
758 LLINK(pp) = RLINK(p);
759 else
760 RLINK(pp) = RLINK(p);
761 break;
762 }
763
764 if (RLINK(p) == Node::NullPtr) // missing right child?
765 { // yes: link pp to p's child
766 if (LLINK(pp) == p)
767 LLINK(pp) = LLINK(p);
768 else
769 RLINK(pp) = LLINK(p);
770 break;
771 }
772
773 // here p is a full node ==> swap with successor
774 swapWithSuccessor(p, pp, path);
775 // removed_key = KEY(succ); // AH_ERROR remove
776 }
777
778 p->reset();
779
780 if (pp == head_ptr) // check if the root was removed
781 return p; // balance factors unchanged ==> AVL condition is not violated
782
783 restore_avl_after_deletion(left_deficit, path);
784
785 return p;
786 }
787
790 [[nodiscard]] bool verify() const
791 {
792 return is_avl(root) and check_bst(root, cmp);
793 }
794
803 struct Iterator : public BinNodeInfixIterator<Node>
804 {
806 Iterator() noexcept = default;
807
809
811 };
812};
813
828template <typename Key, class Compare = Aleph::less<Key>>
829 requires StrictWeakOrder<Compare, Key>
830struct Avl_Tree : public Gen_Avl_Tree<AvlNode, Key, Compare>
831{
833 using Base::Base;
834};
835
850template <typename Key, class Compare = Aleph::less<Key>>
852struct Avl_Tree_Vtl : public Gen_Avl_Tree<AvlNodeVtl, Key, Compare>
853{
855 using Base::Base;
856};
857} // end namespace Aleph
858#endif // TPL_AVL_H
C++20 concepts hub: comparison, BST policy, and Aleph container concepts.
#define AH_ERROR(...)
Print an error message (always enabled).
Definition ahDefs.H:270
Standard functor implementations and comparison objects.
AVL tree node with balance factor.
bool is_avl(Node *p)
Validate that a tree satisfies AVL properties.
Definition avlNode.H:160
#define DIFF(p)
Access the balance factor of node p.
Definition avlNode.H:95
@ KEY
Definition btreepic.C:169
Inorder iterator on the nodes of a binary tree.
AVL balanced binary search tree.
Definition tpl_avl.H:105
Node * search_and_stack_avl(const Key &key, signed char &cmp_result, Path &path) noexcept(nothrow_compare_v< Compare, Key >)
Definition tpl_avl.H:129
Node head_node
The type of node.
Definition tpl_avl.H:110
Node * insert(Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Insert the node pointed by p in the tree.
Definition tpl_avl.H:640
static Node * restore_avl(Node *p, Node *pp) noexcept
Definition tpl_avl.H:342
Gen_Avl_Tree(const Gen_Avl_Tree &)=delete
Not copyable: the tree does not own its nodes, and a copy would hold the same ones.
Gen_Avl_Tree(Compare _cmp) noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_constructible_v< Compare, Compare & >)
Builds an empty tree with the comparison criteria _cmp.
Definition tpl_avl.H:519
Node * remove(const Key &key) noexcept(nothrow_compare_v< Compare, Key >)
Remove from an AVL tree the node containing key key.
Definition tpl_avl.H:738
Node * swapWithSuccessor(Node *p, Node *&pp, Path &path) noexcept
Definition tpl_avl.H:402
void restore_avl_after_insertion(Node *p, Path &path) noexcept
Definition tpl_avl.H:367
Node * search_or_insert(Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Search or insert a key.
Definition tpl_avl.H:680
virtual ~Gen_Avl_Tree() noexcept=default
bool verify() const
Return true if the tree is a valid AVL tree: the balance of every node and the order of the keys.
Definition tpl_avl.H:790
static bool at_head(const Path &path) noexcept
true when path holds only the head node.
Definition tpl_avl.H:122
Gen_Avl_Tree(Gen_Avl_Tree &&tree) noexcept(bin_node_detail::nothrow_header_from_v< Node > and bin_node_detail::nothrow_compare_taken_v< Compare >)
Takes the nodes and the comparison criteria of tree, which is left empty and can take nodes again.
Definition tpl_avl.H:557
constexpr Compare & get_compare() noexcept
See key_comp().
Definition tpl_avl.H:484
constexpr Node *& getRoot() noexcept
Return a modifiable reference to tree's root.
Definition tpl_avl.H:586
Node * insert_dup(Node *p) noexcept(nothrow_compare_v< Compare, Key >)
Insert the node p without testing for key duplicity.
Definition tpl_avl.H:710
static Node * doubleRotateLeft(Node *p) noexcept
Definition tpl_avl.H:239
constexpr Compare & key_comp() noexcept
The key type.
Definition tpl_avl.H:478
void restore_avl_after_deletion(bool left_deficit, Path &path) noexcept
Definition tpl_avl.H:451
void swap(Gen_Avl_Tree &tree) noexcept(std::is_nothrow_swappable_v< Compare >)
Swap in constant time all the items of this with the items of tree.
Definition tpl_avl.H:575
Gen_Avl_Tree() noexcept(std::is_nothrow_default_constructible_v< Node > and std::is_nothrow_default_constructible_v< Compare > and std::is_nothrow_constructible_v< Compare, Compare & >)
Builds an empty tree with a comparison criteria built by default.
Definition tpl_avl.H:502
NodeType< Key > Node
Definition tpl_avl.H:107
static Rotation_Type rotation_type(Node *p) noexcept
Definition tpl_avl.H:321
Node * search(const Key &key) const noexcept(nothrow_compare_v< Compare, Key >)
Search a node containing key.
Definition tpl_avl.H:607
Gen_Avl_Tree & operator=(const Gen_Avl_Tree &)=delete
Not copyable, for the same reason as the copy constructor.
Node * search_dup_and_stack_avl(const Key &key, signed char &cmp_result, Path &path) noexcept(nothrow_compare_v< Compare, Key >)
Definition tpl_avl.H:172
constexpr Node * getRoot() const noexcept
Return a modifiable reference to tree's root.
Definition tpl_avl.H:592
static Node * doubleRotateRight(Node *p) noexcept
Definition tpl_avl.H:276
static Node * rotateRight(Node *p) noexcept
Definition tpl_avl.H:219
static Node * rotateLeft(Node *p) noexcept
Definition tpl_avl.H:199
Stack of fixed capacity whose storage is inside the object.
T & push(const T &data) noexcept
Push a copy of data.
T & top() noexcept
Return a modifiable reference to the top; the stack must not be empty.
Strict weak ordering constraint for BST comparators.
bool check_bst(Node *p, const Compare &cmp=Compare())
Return true if p is a binary search tree.
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
@ CmpGreater
First argument is greater than second.
@ CmpLess
First argument is less than second.
@ CmpEqual
Arguments are equal.
STL namespace.
AVL binary search tree with nodes with a virtual destructor.
Definition tpl_avl.H:853
AVL binary search tree with nodes without a virtual destructor.
Definition tpl_avl.H:831
Iterator over the nodes.
Definition tpl_avl.H:804
Iterator() noexcept=default
Default constructor creates an "end" iterator.
Iterator(const Gen_Avl_Tree &tree)
Definition tpl_avl.H:810
#define RLINK(i, n)
#define LLINK(i, n)
Gsl_Compatible_Rng r
Stack implementations backed by dynamic or fixed arrays.
Utility functions for binary tree operations.