5#include "Stroika/Foundation/Containers/Private/IteratorImplHelper.h"
17 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
18 template <qCompilerAndStdLib_Constra
intDiffersInTemplateRedeclaration_BWA (IThreeWayComparer<KEY_TYPE>) KEY_THREEWAY_COMPARER>
19 class SortedMapping_SkipList<KEY_TYPE, MAPPED_VALUE_TYPE>::Rep_
20 :
public Private::SkipListBasedContainerRepImpl<Rep_<KEY_THREEWAY_COMPARER>, IImplRepBase_>,
21 public Memory::UseBlockAllocationIfAppropriate<Rep_<KEY_THREEWAY_COMPARER>> {
26 using inherited = Private::SkipListBasedContainerRepImpl<Rep_<KEY_THREEWAY_COMPARER>, IImplRepBase_>;
37 Rep_ (
const Rep_&
from) =
default;
40 nonvirtual Rep_& operator= (
const Rep_&) =
delete;
47 return Memory::MakeSharedPtr<Rep_> (*
this);
54 virtual size_t size ()
const override
58 return fData_.size ();
60 virtual bool empty ()
const override
64 return fData_.empty ();
80 virtual KeyEqualsCompareFunctionType GetKeyEqualsComparer ()
const override
83 return Common::EqualsComparerAdapter<KEY_TYPE, KEY_THREEWAY_COMPARER>{fData_.key_comp ()};
88 return Memory::MakeSharedPtr<Rep_> (fData_.key_comp ());
94 auto result = Memory::MakeSharedPtr<Rep_> (*
this);
95 result->fData_.MoveIteratorHereAfterClone (&Debug::UncheckedDynamicCast<const IteratorRep_&> (i->ConstGetRep ()).fIterator, &fData_);
102 auto i = fData_.Find (
key);
103 if (i == fData_.end ()) {
104 if (
item !=
nullptr) {
110 if (
item !=
nullptr) {
125 result = fData_.Add (
key, newElt);
129 if (fData_.Find (
key)) {
133 fData_.Add (
key, newElt);
147 if (
auto i = fData_.Find (
key)) {
149 fChangeCounts_.PerformedChange ();
156 Require (
not i.Done ());
158 auto&
mir = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ());
159 mir.fIterator.AssertDataMatches (&fData_);
160 if (
nextI ==
nullptr) {
161 fData_.Remove (
mir.fIterator);
162 fChangeCounts_.PerformedChange ();
165 auto ret = fData_.erase (
mir.fIterator);
166 fChangeCounts_.PerformedChange ();
174 if (
nextI !=
nullptr) {
175 savedUnderlyingIndex = Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ()).fIterator.GetUnderlyingIteratorRep ();
177 fData_.Update (Debug::UncheckedDynamicCast<const IteratorRep_&> (i.ConstGetRep ()).fIterator,
newValue);
178 fChangeCounts_.PerformedChange ();
179 if (
nextI !=
nullptr) {
189 return fData_.key_comp ();
194 using IteratorRep_ = Private::IteratorImplHelper_<value_type, DataStructureImplType_>;
197 DataStructureImplType_ fData_;
209 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
211 requires (three_way_comparable<KEY_TYPE>)
214 AssertRepValidType_ ();
216 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
217 template <IThreeWayComparer<KEY_TYPE> KEY_THREEWAY_COMPARER>
219 : inherited{Memory::MakeSharedPtr<Rep_<remove_cvref_t<KEY_THREEWAY_COMPARER>>> (move (src))}
221 AssertRepValidType_ ();
223 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
224 template <IThreeWayComparer<KEY_TYPE> KEY_THREEWAY_COMPARER>
226 : inherited{Memory::MakeSharedPtr<Rep_<remove_cvref_t<KEY_THREEWAY_COMPARER>>> (keyComparer)}
228 AssertRepValidType_ ();
230 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
232 requires (three_way_comparable<KEY_TYPE>)
233 : SortedMapping_SkipList{}
236 AssertRepValidType_ ();
238 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
239 template <IThreeWayComparer<KEY_TYPE> KEY_THREEWAY_COMPARER>
241 const initializer_list<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>>& src)
242 : SortedMapping_SkipList{forward<KEY_THREEWAY_COMPARER> (keyComparer)}
245 AssertRepValidType_ ();
247#if !qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
248 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
249 template <IIterableOfTo<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>> ITERABLE_OF_ADDABLE>
250 requires (not derived_from<remove_cvref_t<ITERABLE_OF_ADDABLE>, SortedMapping_SkipList<KEY_TYPE, MAPPED_VALUE_TYPE>>)
252 requires (three_way_comparable<KEY_TYPE>)
253 : SortedMapping_SkipList{}
255 this->AddAll (forward<ITERABLE_OF_ADDABLE> (src));
256 AssertRepValidType_ ();
259 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
260 template <IThreeWayComparer<KEY_TYPE> KEY_THREEWAY_COMPARER, IIterableOfTo<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>> ITERABLE_OF_ADDABLE>
262 : SortedMapping_SkipList{forward<KEY_THREEWAY_COMPARER> (keyComparer)}
265 AssertRepValidType_ ();
267 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
268 template <IInputIterator<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>> ITERATOR_OF_ADDABLE>
270 requires (three_way_comparable<KEY_TYPE>)
271 : SortedMapping_SkipList{}
273 this->AddAll (forward<ITERATOR_OF_ADDABLE> (start), forward<ITERATOR_OF_ADDABLE> (end));
274 AssertRepValidType_ ();
276 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
277 template <IThreeWayComparer<KEY_TYPE> KEY_THREEWAY_COMPARER, IInputIterator<KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>> ITERATOR_OF_ADDABLE>
279 ITERATOR_OF_ADDABLE&& start, ITERATOR_OF_ADDABLE&& end)
280 : SortedMapping_SkipList{forward<KEY_THREEWAY_COMPARER> (keyComparer)}
283 AssertRepValidType_ ();
285 template <
typename KEY_TYPE,
typename MAPPED_VALUE_TYPE>
286 inline void SortedMapping_SkipList<KEY_TYPE, MAPPED_VALUE_TYPE>::AssertRepValidType_ ()
const
289 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 AssertNotReached()
#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...
SortedMapping_SkipList<KEY_TYPE, MAPPED_VALUE_TYPE, TRAITS> is an SkipList-based concrete implementat...
nonvirtual CONTAINER_OF_Key_T As() const
nonvirtual bool Add(ArgByValueType< key_type > key, ArgByValueType< mapped_type > newElt, AddReplaceMode addReplaceMode=AddReplaceMode::eAddReplaces)
nonvirtual optional< mapped_type > Lookup(ArgByValueType< key_type > key) const
nonvirtual unsigned int AddAll(ITERABLE_OF_ADDABLE &&items, AddReplaceMode addReplaceMode=AddReplaceMode::eAddReplaces)
nonvirtual void Update(const Iterator< value_type > &i, ArgByValueType< mapped_type > newValue, Iterator< value_type > *nextI=nullptr)
nonvirtual bool RemoveIf(ArgByValueType< key_type > key)
Remove the given item, if it exists. Return true if found and removed.
nonvirtual void Remove(ArgByValueType< key_type > key)
Remove the given item (which must exist).
nonvirtual KeyThreeWayComparerType GetKeyThreeWayComparer() 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 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'.
AddReplaceMode
Mode flag to say if Adding to a container replaces, or if the first addition wins.
SequencePolicy
equivalent which of 4 types being used std::execution::sequenced_policy, parallel_policy,...
auto Finally(FUNCTION &&f) -> Private_::FinallySentry< FUNCTION >