Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
SortedKeyedCollection_SkipList.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4
5#ifndef _Stroika_Foundation_Containers_Concrete_SortedKeyedCollection_SkipList_h_
6#define _Stroika_Foundation_Containers_Concrete_SortedKeyedCollection_SkipList_h_
7
8#include "Stroika/Foundation/StroikaPreComp.h"
9
10#include "Stroika/Foundation/Containers/DataStructures/SkipList.h"
13
14/**
15 * \file
16 *
17 * \note Code-Status: <a href="Code-Status.md#Beta">Beta</a>
18 *
19 */
21
22 using Common::IThreeWayComparer;
23
24 /**
25 * \brief SortedKeyedCollection_SkipList<T, KEY_TYPE, TRAITS> is an SkipList-based concrete implementation of the SortedKeyedCollection<T, KEY_TYPE, TRAITS> container pattern.
26 *
27 * \note Runtime performance/complexity:
28 * Very good low overhead implementation
29 *
30 * o size () is constant complexity
31 *
32 * \note \em Thread-Safety <a href="Thread-Safety.md#C++-Standard-Thread-Safety">C++-Standard-Thread-Safety</a>
33 */
34 template <typename T, typename KEY_TYPE, typename TRAITS = KeyedCollection_DefaultTraits<T, KEY_TYPE>>
36 : public Private::SkipListBasedContainer<SortedKeyedCollection_SkipList<T, KEY_TYPE, TRAITS>, SortedKeyedCollection<T, KEY_TYPE, TRAITS>, true> {
37 private:
38 using inherited =
40
41 public:
42 using TraitsType = typename inherited::TraitsType;
43 using KeyExtractorType = typename inherited::KeyExtractorType;
44 using KeyEqualityComparerType = typename inherited::KeyEqualityComparerType;
45 using KeyThreeWayComparerType = typename inherited::KeyThreeWayComparerType;
46 using KeyType = typename inherited::KeyType;
47 using key_type = typename inherited::key_type;
48 using value_type = typename inherited::value_type;
49
50 public:
51 template <IThreeWayComparer<KEY_TYPE> KEY_COMPARER = compare_three_way>
52 struct SKIPLIST_ELT_COMPARER {
53 SKIPLIST_ELT_COMPARER (const KeyExtractorType& keyExtractor, const KEY_COMPARER& keyComparer = KEY_COMPARER{})
54 : fKeyExtractor{keyExtractor}
55 , fKeyComparer{keyComparer}
56 {
57 }
58 constexpr auto operator() (const T& l, const T& r) const
59 {
60 return fKeyComparer (fKeyExtractor (l), fKeyExtractor (r));
61 }
62 constexpr auto operator() (const KEY_TYPE& l, const T& r) const
63 {
64 return fKeyComparer (l, fKeyExtractor (r));
65 }
66 constexpr auto operator() (const T& l, const KEY_TYPE& r) const
67 {
68 return fKeyComparer (fKeyExtractor (l), r);
69 }
70 constexpr auto operator() (const KEY_TYPE& l, const KEY_TYPE& r) const
71 {
72 return fKeyComparer (l, r);
73 }
74 [[no_unique_address]] KeyExtractorType fKeyExtractor;
75 [[no_unique_address]] KEY_COMPARER fKeyComparer;
76 };
77
78 /**
79 * AddOrExtendOrReplaceMode::eAddReplaces makes sense cuz KeyedCollection<>::Add () will REPLACE the value.
80 */
81 template <IThreeWayComparer<KEY_TYPE> KEY_COMPARER = compare_three_way>
84
85 /**
86 * \brief SKIPLIST is SkipList that can be used inside SortedMapping_SkipList
87 */
88 template <IThreeWayComparer<KEY_TYPE> KEY_COMPARER = compare_three_way>
90
91 public:
92 template <IThreeWayComparer<KEY_TYPE> COMPARER = compare_three_way>
93 SortedKeyedCollection_SkipList (COMPARER&& keyComparer = COMPARER{})
97 template <IThreeWayComparer<KEY_TYPE> COMPARER = compare_three_way>
98 SortedKeyedCollection_SkipList (const KeyExtractorType& keyExtractor, COMPARER&& keyComparer = COMPARER{});
99 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE, IThreeWayComparer<KEY_TYPE> COMPARER = equal_to<KEY_TYPE>>
101 not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, SortedKeyedCollection_SkipList<T, KEY_TYPE, TRAITS>>)
102 SortedKeyedCollection_SkipList (ITERABLE_OF_ADDABLE&& src)
103#if qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
104 : SortedKeyedCollection_SkipList{KeyExtractorType{}, COMPARER{}}
105 {
106 this->AddAll (src);
107 AssertRepValidType_ ();
108 }
109#endif
110 ;
111 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE, IThreeWayComparer<KEY_TYPE> COMPARER = compare_three_way>
112 SortedKeyedCollection_SkipList (COMPARER&& keyComparer, ITERABLE_OF_ADDABLE&& src)
113 requires (IKeyedCollection_ExtractorCanBeDefaulted<T, KEY_TYPE, TRAITS>);
114 template <IThreeWayComparer<KEY_TYPE> COMPARER, IIterableOfTo<T> ITERABLE_OF_ADDABLE>
115 SortedKeyedCollection_SkipList (const KeyExtractorType& keyExtractor, COMPARER&& keyComparer, ITERABLE_OF_ADDABLE&& src);
116 template <IInputIterator<T> ITERATOR_OF_ADDABLE, IThreeWayComparer<KEY_TYPE> COMPARER = compare_three_way>
117 SortedKeyedCollection_SkipList (ITERATOR_OF_ADDABLE&& start, ITERATOR_OF_ADDABLE&& end)
118 requires (IKeyedCollection_ExtractorCanBeDefaulted<T, KEY_TYPE, TRAITS>);
119 template <IInputIterator<T> ITERATOR_OF_ADDABLE, IThreeWayComparer<KEY_TYPE> COMPARER = compare_three_way>
120 SortedKeyedCollection_SkipList (COMPARER&& keyComparer, ITERATOR_OF_ADDABLE&& start, ITERATOR_OF_ADDABLE&& end)
121 requires (IKeyedCollection_ExtractorCanBeDefaulted<T, KEY_TYPE, TRAITS>);
122 template <IThreeWayComparer<KEY_TYPE> COMPARER, IInputIterator<T> ITERATOR_OF_ADDABLE>
123 SortedKeyedCollection_SkipList (const KeyExtractorType& keyExtractor, COMPARER&& keyComparer, ITERATOR_OF_ADDABLE&& start,
124 ITERATOR_OF_ADDABLE&& end);
125
126 public:
127 /**
128 */
129 nonvirtual SortedKeyedCollection_SkipList& operator= (SortedKeyedCollection_SkipList&&) noexcept = default;
130 nonvirtual SortedKeyedCollection_SkipList& operator= (const SortedKeyedCollection_SkipList&) = default;
131
132 private:
133 using IImplRepBase_ = Private::SkipListBasedContainerIRep<typename SortedKeyedCollection<T, KEY_TYPE, TRAITS>::_IRep>;
134 template <qCompilerAndStdLib_ConstraintDiffersInTemplateRedeclaration_BWA (IThreeWayComparer<KEY_TYPE>) COMPARER>
135 class Rep_;
136
137 private:
138 nonvirtual void AssertRepValidType_ () const;
139
140 private:
141 friend inherited;
142 };
143
144}
145
146/*
147 ********************************************************************************
148 ******************************* Implementation Details *************************
149 ********************************************************************************
150 */
151#include "SortedKeyedCollection_SkipList.inl"
152
153#endif /*_Stroika_Foundation_Containers_Concrete_SortedKeyedCollection_SkipList_h_ */
SortedKeyedCollection_SkipList<T, KEY_TYPE, TRAITS> is an SkipList-based concrete implementation of t...
SkipListBasedContainer is a Stroika implementation detail, but its public methods are fair game and f...
A SortedKeyedCollection is a KeyedCollection<T> which remains sorted (iteration produces items sorted...