4#include "Stroika/Foundation/Containers/DataStructures/SkipList.h"
5#include "Stroika/Foundation/Containers/Private/IteratorImplHelper.h"
17 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (Common::IThreeWayComparer<T>) COMPARER>
18 class SortedCollection_SkipList<T>::Rep_ :
public Private::SkipListBasedContainerRepImpl<Rep_<COMPARER>, IImplRepBase_>,
19 public Memory::UseBlockAllocationIfAppropriate<Rep_<COMPARER>> {
21 using inherited = Private::SkipListBasedContainerRepImpl<Rep_<COMPARER>, IImplRepBase_>;
31 Rep_ (
const Rep_&
from) =
default;
34 nonvirtual Rep_& operator= (
const Rep_&) =
delete;
41 return Memory::MakeSharedPtr<Rep_> (*
this);
48 virtual size_t size ()
const override
51 return fData_.size ();
53 virtual bool empty ()
const override
56 return fData_.empty ();
67 if (
auto iLink = fData_.Find ([&] (
auto arg) { return that (arg.fKey); })) {
78 return Memory::MakeSharedPtr<Rep_> (fData_.key_comp ());
84 auto result = Memory::MakeSharedPtr<Rep_> (*
this);
85 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i->ConstGetRep ());
86 result->fData_.MoveIteratorHereAfterClone (&
mir.fIterator, &fData_);
90#if qCompilerAndStdLib_MemoryInsertAt_Buggy
93 [[gnu::noinline, gnu::optimize (
"O0")]]
101 for (
const value_type& i :
items) {
104 fChangeCounts_.PerformedChange ();
107 typename DataStructureImplType_::ForwardIterator
retIt;
109 fChangeCounts_.PerformedChange ();
116 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
117 fData_.Remove (
mir.fIterator);
118 if (
nextI ==
nullptr) {
120 fChangeCounts_.PerformedChange ();
123 typename DataStructureImplType_::ForwardIterator
retIt;
125 fChangeCounts_.PerformedChange ();
132 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
134 fData_.Remove (
mir.fIterator);
135 fChangeCounts_.PerformedChange ();
138 auto ret = fData_.erase (
mir.fIterator);
139 fChangeCounts_.PerformedChange ();
149 return fData_.key_comp ();
154 return not fData_.Find (
item).AtEnd ();
159 fData_.Remove (
item);
160 fChangeCounts_.PerformedChange ();
165 struct IterTraits_ : Private::IteratorImplHelper_DefaultTraits<value_type, DataStructureImplType_> {
166 static constexpr value_type ConvertDataStructureIterationResult2ContainerIteratorResult (
const typename DataStructureImplType_::value_type& t)
171 using IteratorRep_ = Private::IteratorImplHelper_<value_type, DataStructureImplType_, IterTraits_>;
174 DataStructureImplType_ fData_;
186 template <
typename T>
190 AssertRepValidType_ ();
192 template <
typename T>
193 template <IThreeWayComparer<T> COMPARER>
195 : inherited{Memory::MakeSharedPtr<Rep_<remove_cvref_t<COMPARER>>> (inorderComparer)}
197 AssertRepValidType_ ();
199 template <
typename T>
201 : SortedCollection_SkipList{}
204 AssertRepValidType_ ();
206 template <
typename T>
207 template <IThreeWayComparer<T> COMPARER>
209 : SortedCollection_SkipList{forward<COMPARER> (inOrderComparer)}
212 AssertRepValidType_ ();
214#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
215 template <
typename T>
216 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
217 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, SortedCollection_SkipList<T>>)
219 : SortedCollection_SkipList{}
221 this->AddAll (forward<ITERABLE_OF_ADDABLE> (src));
222 AssertRepValidType_ ();
225 template <
typename T>
226 template <IThreeWayComparer<T> COMPARER, IIterableOfTo<T> ITERABLE_OF_ADDABLE>
228 : SortedCollection_SkipList{forward<COMPARER> (inOrderComparer)}
231 AssertRepValidType_ ();
233 template <
typename T>
234 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
236 : SortedCollection_SkipList{}
239 AssertRepValidType_ ();
241 template <
typename T>
242 template <IThreeWayComparer<T> COMPARER, IInputIterator<T> ITERATOR_OF_ADDABLE>
244 : SortedCollection_SkipList{forward<COMPARER> (inOrderComparer)}
247 AssertRepValidType_ ();
249 template <
typename T>
250 inline void SortedCollection_SkipList<T>::AssertRepValidType_ ()
const
253 typename inherited::template _SafeReadRepAccessor<IImplRepBase_> tmp{
this};
#define qStroika_Foundation_Debug_AssertionsChecked
The qStroika_Foundation_Debug_AssertionsChecked flag determines if assertions are checked and validat...
#define RequireNotNull(p)
#define qStroika_ATTRIBUTE_NO_UNIQUE_ADDRESS_VCFORCE
[[msvc::no_unique_address]] isn't always broken in MSVC. Annotate with this on things where its not b...
nonvirtual void AddAll(ITERATOR_OF_ADDABLE &&start, ITERATOR_OF_ADDABLE2 &&end)
nonvirtual void Update(const Iterator< value_type > &i, ArgByValueType< value_type > newValue, Iterator< value_type > *nextI=nullptr)
nonvirtual void Add(ArgByValueType< value_type > item)
SortedCollection_SkipList<T> is an SkipList-based concrete implementation of the SortedCollection<T> ...
SortedCollection_SkipList()
nonvirtual ElementThreeWayComparerType GetElementThreeWayComparer() const
nonvirtual bool Contains(ArgByValueType< T > item) const
Compares items with the already associated GetInOrderComparer(), and returns true if the item is foun...
unique_lock< AssertExternallySynchronizedChecker > WriteContext
Instantiate AssertExternallySynchronizedChecker::WriteContext to designate an area of code where prot...
shared_lock< const AssertExternallySynchronizedChecker > ReadContext
Instantiate AssertExternallySynchronizedChecker::ReadContext to designate an area of code where prote...
nonvirtual Iterator< T > Find(THAT_FUNCTION &&that) const
Run the argument bool-returning function (or lambda) on the elements of the container,...
nonvirtual CONTAINER_OF_T As(CONTAINER_OF_T_CONSTRUCTOR_ARGS... args) const
nonvirtual size_t size() const
Returns the number of items contained.
nonvirtual void Apply(const function< void(ArgByValueType< T > item)> &doToElement) const
Run the argument function (or lambda) on each element of the container.
nonvirtual bool empty() const
Returns true iff size() == 0.
static constexpr default_sentinel_t end() noexcept
Support for ranged for, and STL syntax in general.
nonvirtual Iterator< T > MakeIterator() const
Create an iterator object which can be used to traverse the 'Iterable'.
SequencePolicy
equivalent which of 4 types being used std::execution::sequenced_policy, parallel_policy,...