5#include "Stroika/Foundation/Containers/Private/IteratorImplHelper.h"
17 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IThreeWayComparer<T>) COMPARER>
18 class SortedSet_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
52 return fData_.size ();
54 virtual bool empty ()
const override
58 return fData_.empty ();
63 fData_.Apply ([&] (
const auto& k) {
doToElement (k.fKey); });
73 auto found = fData_.Find (v);
76 (
found == Debug::UncheckedDynamicCast<const IteratorRep_&> (this->inherited::Find_equal_to (v,
seq).ConstGetRep ())
77 .fIterator.GetUnderlyingIteratorRep ()));
87 return Common::EqualsComparerAdapter<T, COMPARER>{fData_.key_comp ()};
92 return Memory::MakeSharedPtr<Rep_> (fData_.key_comp ());
98 auto result = Memory::MakeSharedPtr<Rep_> (*
this);
99 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i->ConstGetRep ());
100 result->fData_.MoveIteratorHereAfterClone (&
mir.fIterator, &fData_);
104 virtual bool Equals (
const typename Iterable<value_type>::_IRep&
rhs)
const override
107 return this->_Equals_Reference_Implementation (
rhs);
112 auto i = fData_.Find (
item);
113 bool notDone = i != fData_.end ();
126 fChangeCounts_.PerformedChange ();
132 auto i = fData_.Find (
item);
133 if (i != fData_.end ()) [[
likely]] {
135 fChangeCounts_.PerformedChange ();
142 Require (
not i.Done ());
143 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
144 mir.fIterator.AssertDataMatches (&fData_);
145 if (
nextI ==
nullptr) {
146 fData_.Remove (
mir.fIterator);
147 fChangeCounts_.PerformedChange ();
150 auto ret = fData_.erase (
mir.fIterator);
151 fChangeCounts_.PerformedChange ();
161 return fData_.key_comp ();
166 struct IterTraits_ : Private::IteratorImplHelper_DefaultTraits<value_type, DataStructureImplType_> {
167 static constexpr value_type ConvertDataStructureIterationResult2ContainerIteratorResult (
const typename DataStructureImplType_::value_type& t)
172 using IteratorRep_ = Private::IteratorImplHelper_<value_type, DataStructureImplType_, IterTraits_>;
175 DataStructureImplType_ fData_;
187 template <
typename T>
191 AssertRepValidType_ ();
193 template <
typename T>
194 template <IThreeWayComparer<T> COMPARER>
196 : inherited{Memory::MakeSharedPtr<Rep_<remove_cvref_t<COMPARER>>> (forward<COMPARER> (comparer))}
198 AssertRepValidType_ ();
200 template <
typename T>
202 : SortedSet_SkipList{}
205 AssertRepValidType_ ();
207 template <
typename T>
208 template <IThreeWayComparer<T> COMPARER>
210 : SortedSet_SkipList{forward<COMPARER> (comparer)}
213 AssertRepValidType_ ();
215#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
216 template <
typename T>
217 template <IIterableOfTo<T> ITERABLE_OF_ADDABLE>
218 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, SortedSet_SkipList<T>>)
220 : SortedSet_SkipList{}
222 this->AddAll (forward<ITERABLE_OF_ADDABLE> (src));
223 AssertRepValidType_ ();
226 template <
typename T>
227 template <IThreeWayComparer<T> COMPARER, IIterableOfTo<T> ITERABLE_OF_ADDABLE>
229 : SortedSet_SkipList (forward<COMPARER> (comparer))
232 AssertRepValidType_ ();
234 template <
typename T>
235 template <IInputIterator<T> ITERATOR_OF_ADDABLE>
237 : SortedSet_SkipList{}
240 AssertRepValidType_ ();
242 template <
typename T>
243 template <IThreeWayComparer<T> COMPARER, IInputIterator<T> ITERATOR_OF_ADDABLE>
245 : SortedSet_SkipList (forward<COMPARER> (comparer))
248 AssertRepValidType_ ();
250 template <
typename T>
251 inline void SortedSet_SkipList<T>::AssertRepValidType_ ()
const
254 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)
bool Equals(const T *lhs, const T *rhs)
strcmp or wsccmp() as appropriate == 0
#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...
SortedSet_SkipList<T> is an std::set-based concrete implementation of the SortedSet<T> container patt...
nonvirtual optional< value_type > Lookup(ArgByValueType< value_type > item) const
nonvirtual ElementEqualityComparerType GetElementEqualsComparer() const
nonvirtual Set CloneEmpty() const
for return Set<T> { s->GetEqualsComparer(); } - except more efficient - clones settings/dynamic subty...
nonvirtual void Remove(ArgByValueType< value_type > item)
Remove the item (given by value or iterator pointing to it) from the contain. The item MUST exist.
nonvirtual bool RemoveIf(ArgByValueType< value_type > item)
nonvirtual void Add(ArgByValueType< value_type > item)
nonvirtual void AddAll(ITERATOR_OF_ADDABLE &&start, ITERATOR_OF_ADDABLE2 &&end)
nonvirtual ElementThreeWayComparerType GetElementThreeWayComparer() const
shared_lock< const AssertExternallySynchronizedMutex > ReadContext
Instantiate AssertExternallySynchronizedMutex::ReadContext to designate an area of code where protect...
unique_lock< AssertExternallySynchronizedMutex > WriteContext
Instantiate AssertExternallySynchronizedMutex::WriteContext to designate an area of code where protec...
nonvirtual void Apply(const function< void(ArgByValueType< T > item)> &doToElement, Execution::SequencePolicy seq=Execution::SequencePolicy::eDEFAULT) const
Run the argument function (or lambda) on each element of the container.
nonvirtual Iterator< T > Find(THAT_FUNCTION &&that, Execution::SequencePolicy seq=Execution::SequencePolicy::eDEFAULT) const
Run the argument bool-returning function (or lambda) on each element 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 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,...