50#ifndef GUM_SHARED_AVL_TREE_H
51#define GUM_SHARED_AVL_TREE_H
57#ifndef DOXYGEN_SHOULD_SKIP_THIS
61 template <
typename Val,
typename Cmp >
62 class SharedAVLTreeIterator;
63 template <
typename Val,
typename Cmp >
64 class SharedAVLTreeIteratorSafe;
66 template <
typename Val,
typename Cmp >
67 class SharedAVLTreeReverseIterator;
68 template <
typename Val,
typename Cmp >
69 class SharedAVLTreeReverseIteratorSafe;
81 template <
typename Val,
typename Cmp = std::less< Val > >
82 class SharedAVLTree:
private AVLTree< Val, Cmp > {
86 using value_type = Val;
87 using reference = Val&;
88 using const_reference =
const Val&;
90 using const_pointer =
const Val*;
91 using iterator = SharedAVLTreeIterator< Val, Cmp >;
92 using iterator_safe = SharedAVLTreeIteratorSafe< Val, Cmp >;
93 using reverse_iterator = SharedAVLTreeReverseIterator< Val, Cmp >;
94 using reverse_iterator_safe = SharedAVLTreeReverseIteratorSafe< Val, Cmp >;
95 using AVLNode = AVLTreeNode< Val >;
110 explicit SharedAVLTree(
const Cmp& compare = Cmp());
116 SharedAVLTree(SharedAVLTree< Val, Cmp >&& from)
noexcept;
136 SharedAVLTree< Val, Cmp >& operator=(SharedAVLTree< Val, Cmp >&& from);
149 using AVLTree< Val, Cmp >::size;
155 using AVLTree< Val, Cmp >::empty;
162 using AVLTree< Val, Cmp >::contains;
169 using AVLTree< Val, Cmp >::exists;
173 AVLNode* highestNode() const noexcept;
177 using AVLTree< Val, Cmp >::highestValue;
181 AVLNode* lowestNode() const noexcept;
185 using AVLTree< Val, Cmp >::lowestValue;
188 void insert(AVLNode* node);
192 void erase(AVLNode* node);
201 void erase(iterator_safe& iter);
210 void erase(reverse_iterator_safe& iter);
213 using AVLTree< Val, Cmp >::clear;
218 using AVLTree< Val, Cmp >::toString;
228 iterator begin() const;
231 constexpr const iterator& end() const;
234 reverse_iterator rbegin() const;
237 constexpr const reverse_iterator& rend() const;
240 iterator_safe beginSafe();
243 constexpr const iterator_safe& endSafe() const;
246 reverse_iterator_safe rbeginSafe();
249 constexpr const reverse_iterator_safe& rendSafe() const;
256 SharedAVLTree(const SharedAVLTree< Val, Cmp >& from) = delete;
257 SharedAVLTree< Val, Cmp >& operator=(const SharedAVLTree< Val, Cmp >& from) = delete;
262 friend reverse_iterator;
263 friend iterator_safe;
264 friend reverse_iterator_safe;
277 template < typename Val, typename Cmp = std::less< Val > >
278 class SharedAVLTreeIterator: protected AVLTreeIterator< Val, Cmp > {
282 using iterator_category = std::bidirectional_iterator_tag;
283 using AVLNode = AVLTreeNode< Val >;
284 using value_type = AVLNode;
285 using reference = value_type&;
286 using const_reference =
const value_type&;
287 using pointer = value_type*;
288 using const_pointer =
const value_type*;
303 explicit SharedAVLTreeIterator(
const SharedAVLTree< Val, Cmp >& tree,
304 const bool begin =
true) noexcept;
306# ifndef DOXYGEN_SHOULD_SKIP_THIS
309 explicit consteval SharedAVLTreeIterator(StaticInitializer init) noexcept :
310 AVLTreeIterator< Val, Cmp >(init) {}
314 SharedAVLTreeIterator(
const SharedAVLTreeIterator< Val, Cmp >& from)
noexcept;
317 SharedAVLTreeIterator(SharedAVLTreeIterator< Val, Cmp >&& from)
noexcept;
320 ~SharedAVLTreeIterator() noexcept;
331 SharedAVLTreeIterator< Val, Cmp >&
332 operator=(const SharedAVLTreeIterator< Val, Cmp >& from) noexcept;
335 SharedAVLTreeIterator< Val, Cmp >& operator=(SharedAVLTreeIterator< Val, Cmp >&& from) noexcept;
338 bool operator==(const SharedAVLTreeIterator< Val, Cmp >& from) const;
341 bool operator!=(const SharedAVLTreeIterator< Val, Cmp >& from) const;
346 SharedAVLTreeIterator< Val, Cmp >& operator++() noexcept;
351 SharedAVLTreeIterator< Val, Cmp >& operator+=(const Size k) noexcept;
356 SharedAVLTreeIterator< Val, Cmp >& operator--() noexcept;
361 SharedAVLTreeIterator< Val, Cmp >& operator-=(const Size k) noexcept;
369 const_reference operator*() const;
372 const_pointer operator->() const;
377 friend AVLTree< Val, Cmp >;
378 friend SharedAVLTree< Val, Cmp >;
391 template < typename Val, typename Cmp = std::less< Val > >
392 class SharedAVLTreeIteratorSafe: protected AVLTreeIteratorSafe< Val, Cmp > {
396 using iterator_category = std::bidirectional_iterator_tag;
397 using AVLNode = AVLTreeNode< Val >;
398 using value_type = AVLNode;
399 using reference = value_type&;
400 using const_reference =
const value_type&;
401 using pointer = value_type*;
402 using const_pointer =
const value_type*;
417 explicit SharedAVLTreeIteratorSafe(SharedAVLTree< Val, Cmp >& tree,
const bool rbegin =
true);
419# ifndef DOXYGEN_SHOULD_SKIP_THIS
422 explicit consteval SharedAVLTreeIteratorSafe(StaticInitializer init) noexcept :
423 AVLTreeIteratorSafe< Val, Cmp >(init) {}
427 SharedAVLTreeIteratorSafe(
const SharedAVLTreeIteratorSafe< Val, Cmp >& from);
430 SharedAVLTreeIteratorSafe(SharedAVLTreeIteratorSafe< Val, Cmp >&& from);
433 ~SharedAVLTreeIteratorSafe() noexcept;
443 SharedAVLTreeIteratorSafe< Val, Cmp >&
444 operator=(const SharedAVLTreeIteratorSafe< Val, Cmp >& from);
447 SharedAVLTreeIteratorSafe< Val, Cmp >& operator=(SharedAVLTreeIteratorSafe< Val, Cmp >&& from);
450 bool operator==(const SharedAVLTreeIteratorSafe< Val, Cmp >& from) const;
453 bool operator!=(const SharedAVLTreeIteratorSafe< Val, Cmp >& from) const;
458 SharedAVLTreeIteratorSafe< Val, Cmp >& operator++() noexcept;
463 SharedAVLTreeIteratorSafe< Val, Cmp >& operator+=(const Size k) noexcept;
468 SharedAVLTreeIteratorSafe< Val, Cmp >& operator--() noexcept;
473 SharedAVLTreeIteratorSafe< Val, Cmp >& operator-=(const Size k) noexcept;
481 const_reference operator*() const;
484 const_pointer operator->() const;
491 friend AVLTree< Val, Cmp >;
492 friend SharedAVLTree< Val, Cmp >;
505 template < typename Val, typename Cmp = std::less< Val > >
506 class SharedAVLTreeReverseIterator: protected SharedAVLTreeIterator< Val, Cmp > {
510 using iterator_category = std::bidirectional_iterator_tag;
511 using AVLNode = AVLTreeNode< Val >;
512 using value_type = AVLNode;
513 using reference = value_type&;
514 using const_reference =
const value_type&;
515 using pointer = value_type*;
516 using const_pointer =
const value_type*;
531 explicit SharedAVLTreeReverseIterator(
const SharedAVLTree< Val, Cmp >& tree,
532 const bool rbegin =
true) noexcept;
534# ifndef DOXYGEN_SHOULD_SKIP_THIS
537 explicit consteval SharedAVLTreeReverseIterator(StaticInitializer init) noexcept :
538 SharedAVLTreeIterator< Val, Cmp >(init) {}
542 SharedAVLTreeReverseIterator(
const SharedAVLTreeReverseIterator< Val, Cmp >& from)
noexcept;
545 SharedAVLTreeReverseIterator(SharedAVLTreeReverseIterator< Val, Cmp >&& from)
noexcept;
548 ~SharedAVLTreeReverseIterator() noexcept;
558 SharedAVLTreeReverseIterator< Val, Cmp >&
559 operator=(const SharedAVLTreeReverseIterator< Val, Cmp >& from) noexcept;
562 SharedAVLTreeReverseIterator< Val, Cmp >&
563 operator=(SharedAVLTreeReverseIterator< Val, Cmp >&& from) noexcept;
566 bool operator==(const SharedAVLTreeReverseIterator< Val, Cmp >& from) const;
569 bool operator!=(const SharedAVLTreeReverseIterator< Val, Cmp >& from) const;
574 SharedAVLTreeReverseIterator< Val, Cmp >& operator++() noexcept;
579 SharedAVLTreeReverseIterator< Val, Cmp >& operator+=(const Size k) noexcept;
584 SharedAVLTreeReverseIterator< Val, Cmp >& operator--() noexcept;
589 SharedAVLTreeReverseIterator< Val, Cmp >& operator-=(const Size k) noexcept;
597 using SharedAVLTreeIterator< Val, Cmp >::operator*;
600 using SharedAVLTreeIterator< Val, Cmp >::operator->;
607 friend AVLTree< Val, Cmp >;
608 friend SharedAVLTree< Val, Cmp >;
621 template < typename Val, typename Cmp = std::less< Val > >
622 class SharedAVLTreeReverseIteratorSafe: protected SharedAVLTreeIteratorSafe< Val, Cmp > {
626 using iterator_category = std::bidirectional_iterator_tag;
627 using AVLNode = AVLTreeNode< Val >;
628 using value_type = AVLNode;
629 using reference = value_type&;
630 using const_reference =
const value_type&;
631 using pointer = value_type*;
632 using const_pointer =
const value_type*;
647 explicit SharedAVLTreeReverseIteratorSafe(SharedAVLTree< Val, Cmp >& tree,
648 const bool rbegin =
true);
650# ifndef DOXYGEN_SHOULD_SKIP_THIS
653 explicit consteval SharedAVLTreeReverseIteratorSafe(StaticInitializer init) noexcept :
654 SharedAVLTreeIteratorSafe< Val, Cmp >(init) {}
658 SharedAVLTreeReverseIteratorSafe(
const SharedAVLTreeReverseIteratorSafe< Val, Cmp >& from);
661 SharedAVLTreeReverseIteratorSafe(SharedAVLTreeReverseIteratorSafe< Val, Cmp >&& from);
664 ~SharedAVLTreeReverseIteratorSafe() noexcept;
674 SharedAVLTreeReverseIteratorSafe< Val, Cmp >&
675 operator=(const SharedAVLTreeReverseIteratorSafe< Val, Cmp >& from);
678 SharedAVLTreeReverseIteratorSafe< Val, Cmp >&
679 operator=(SharedAVLTreeReverseIteratorSafe< Val, Cmp >&& from);
682 bool operator==(const SharedAVLTreeReverseIteratorSafe< Val, Cmp >& from) const;
685 bool operator!=(const SharedAVLTreeReverseIteratorSafe< Val, Cmp >& from) const;
690 SharedAVLTreeReverseIteratorSafe< Val, Cmp >& operator++() noexcept;
695 SharedAVLTreeReverseIteratorSafe< Val, Cmp >& operator+=(const Size k) noexcept;
700 SharedAVLTreeReverseIteratorSafe< Val, Cmp >& operator--() noexcept;
705 SharedAVLTreeReverseIteratorSafe< Val, Cmp >& operator-=(const Size k) noexcept;
713 using SharedAVLTreeIteratorSafe< Val, Cmp >::operator*;
716 using SharedAVLTreeIteratorSafe< Val, Cmp >::operator->;
722 friend AVLTree< Val, Cmp >;
723 friend SharedAVLTree< Val, Cmp >;
727 template < typename Val, typename Cmp >
728 std::ostream& operator<<(std::ostream& stream, const SharedAVLTree< Val, Cmp >& tree) {
729 return stream << tree.toString();
733# ifndef DOXYGEN_SHOULD_SKIP_THIS
742 extern const SharedAVLTreeIterator< int, std::less< int > > _static_SharedAVLTree_end_;
743 extern const SharedAVLTreeReverseIterator< int, std::less< int > > _static_SharedAVLTree_rend_;
744 extern const SharedAVLTreeIteratorSafe< int, std::less< int > > _static_SharedAVLTree_end_safe_;
745 extern const SharedAVLTreeReverseIteratorSafe< int, std::less< int > >
746 _static_SharedAVLTree_rend_safe_;
748 inline constexpr void*
const _SharedAVLTree_end_ = (
void*
const)&_static_SharedAVLTree_end_;
749 inline constexpr void*
const _SharedAVLTree_rend_ = (
void*
const)&_static_SharedAVLTree_rend_;
750 inline constexpr void*
const _SharedAVLTree_end_safe_
751 = (
void*
const)&_static_SharedAVLTree_end_safe_;
752 inline constexpr void*
const _SharedAVLTree_rend_safe_
753 = (
void*
const)&_static_SharedAVLTree_rend_safe_;
gum is the global namespace for all aGrUM entities