#include <Mapping.h>
Classes | |
class | _IRep |
Implementation detail for Mapping<T> implementors. More... | |
struct | EqualsComparer |
Compare Mappings<>s for equality. Note this can be costly, as the Mappings are not necessarily in the same order. More... | |
Public Types | |
using | ArchetypeContainerType = Mapping |
using | value_type = typename inherited::value_type |
using | key_type = KEY_TYPE |
using | mapped_type = MAPPED_VALUE_TYPE |
using | KeyEqualsCompareFunctionType = Common::ComparisonRelationDeclaration< Common::ComparisonRelationType::eEquals, function< bool(ArgByValueType< key_type >, ArgByValueType< key_type >)> > |
![]() | |
using | value_type = T |
value_type is an alias for the type iterated over - like vector<T>::value_type | |
using | iterator = Iterator< T > |
using | const_iterator = Iterator< T > |
Public Member Functions | |
Mapping () | |
nonvirtual Iterable< key_type > | Keys () const |
nonvirtual Iterable< mapped_type > | MappedValues () const |
nonvirtual optional< mapped_type > | Lookup (ArgByValueType< key_type > key) const |
template<typename THROW_IF_MISSING > | |
nonvirtual mapped_type | LookupChecked (ArgByValueType< key_type > key, const THROW_IF_MISSING &throwIfMissing) const |
nonvirtual mapped_type | LookupValue (ArgByValueType< key_type > key, ArgByValueType< mapped_type > defaultValue=mapped_type{}) const |
nonvirtual add_const_t< mapped_type > | operator[] (ArgByValueType< key_type > key) const |
nonvirtual bool | ContainsKey (ArgByValueType< key_type > key) const |
template<typename VALUE_EQUALS_COMPARER = equal_to<MAPPED_VALUE_TYPE>> | |
nonvirtual bool | ContainsMappedValue (ArgByValueType< mapped_type > v, VALUE_EQUALS_COMPARER &&valueEqualsComparer={}) const |
nonvirtual bool | Add (ArgByValueType< key_type > key, ArgByValueType< mapped_type > newElt, AddReplaceMode addReplaceMode=AddReplaceMode::eAddReplaces) |
template<IIterableOfTo< KeyValuePair< KEY_TYPE, MAPPED_VALUE_TYPE > > ITERABLE_OF_ADDABLE> | |
nonvirtual unsigned int | AddAll (ITERABLE_OF_ADDABLE &&items, AddReplaceMode addReplaceMode=AddReplaceMode::eAddReplaces) |
nonvirtual void | Remove (ArgByValueType< key_type > key) |
Remove the given item (which must exist). | |
nonvirtual bool | RemoveIf (ArgByValueType< key_type > key) |
Remove the given item, if it exists. Return true if found and removed. | |
nonvirtual void | RemoveAll () |
RemoveAll removes all, or all matching (predicate, iterator range, equals comparer or whatever) items. | |
nonvirtual void | Update (const Iterator< value_type > &i, ArgByValueType< mapped_type > newValue, Iterator< value_type > *nextI=nullptr) |
template<IIterableOfTo< KEY_TYPE > ITERABLE_OF_KEY_TYPE> | |
nonvirtual void | RetainAll (const ITERABLE_OF_KEY_TYPE &items) |
template<typename RESULT_CONTAINER = Mapping<KEY_TYPE, MAPPED_VALUE_TYPE>, invocable< KeyValuePair< KEY_TYPE, MAPPED_VALUE_TYPE > > ELEMENT_MAPPER> requires (convertible_to<invoke_result_t<ELEMENT_MAPPER, KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>>, typename RESULT_CONTAINER::value_type> or convertible_to<invoke_result_t<ELEMENT_MAPPER, KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>>, optional<typename RESULT_CONTAINER::value_type>>) | |
nonvirtual RESULT_CONTAINER | Map (ELEMENT_MAPPER &&elementMapper) const |
'override' Iterable<>::Map () function so container template defaults to Mapping, and improve that case to also clone properties like sort order from this mapping | |
template<derived_from< Iterable< KeyValuePair< KEY_TYPE, MAPPED_VALUE_TYPE > > > RESULT_CONTAINER = Mapping<KEY_TYPE, MAPPED_VALUE_TYPE>, typename INCLUDE_PREDICATE > requires (predicate<INCLUDE_PREDICATE, KEY_TYPE> or predicate<INCLUDE_PREDICATE, KeyValuePair<KEY_TYPE, MAPPED_VALUE_TYPE>>) | |
nonvirtual RESULT_CONTAINER | Where (INCLUDE_PREDICATE &&includeIfTrue) const |
template<typename CONTAINER_OF_KEYS > | |
nonvirtual ArchetypeContainerType | WithKeys (const CONTAINER_OF_KEYS &includeKeys) const |
template<typename CONTAINER_OF_Key_T > | |
nonvirtual CONTAINER_OF_Key_T | As () const |
nonvirtual bool | operator== (const Mapping &rhs) const |
compares if the two mappings have the same keys, and corresponding values (doesn't check ordering same). Note this can be costly, as the Mappings are not necessarily in the same order | |
nonvirtual void | Accumulate (ArgByValueType< key_type > key, ArgByValueType< mapped_type > newValue, const function< mapped_type(ArgByValueType< mapped_type >, ArgByValueType< mapped_type >)> &f=[](ArgByValueType< mapped_type > l, ArgByValueType< mapped_type > r) -> mapped_type { return l+r;}, mapped_type initialValue={}) |
like Add (key, newValue) - BUT newValue is COMBINED with the 'f' argument. | |
nonvirtual void | insert (ArgByValueType< value_type > kvp) |
nonvirtual void | erase (ArgByValueType< key_type > key) |
nonvirtual void | clear () |
![]() | |
Iterable (const Iterable &) noexcept=default | |
Iterable are safely copyable (by value). Since Iterable uses COW, this just copies the underlying pointer and increments the reference count. | |
Iterable (Iterable &&) noexcept=default | |
Iterable are safely moveable. | |
template<IIterableOfTo< T > CONTAINER_OF_T> requires (not derived_from<remove_cvref_t<CONTAINER_OF_T>, Iterable<T>>) | |
Iterable (CONTAINER_OF_T &&from) | |
Iterable (const initializer_list< T > &from) | |
nonvirtual | operator bool () const |
nonvirtual Iterator< T > | MakeIterator () const |
Create an iterator object which can be used to traverse the 'Iterable'. | |
nonvirtual size_t | size () const |
Returns the number of items contained. | |
nonvirtual bool | empty () const |
Returns true iff size() == 0. | |
template<Common::IPotentiallyComparer< T > EQUALS_COMPARER = equal_to<T>> | |
nonvirtual bool | Contains (ArgByValueType< T > element, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{}) const |
nonvirtual Iterator< T > | begin () const |
Support for ranged for, and STL syntax in general. | |
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. | |
template<predicate< T > THAT_FUNCTION> | |
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, and return an iterator pointing at the first element (depending on seq) found true. (or use First() to do same thing but return optional<>) | |
template<IIterableOfFrom< T > CONTAINER_OF_T, typename... CONTAINER_OF_T_CONSTRUCTOR_ARGS> | |
nonvirtual CONTAINER_OF_T | As (CONTAINER_OF_T_CONSTRUCTOR_ARGS... args) const |
nonvirtual T | Nth (ptrdiff_t n) const |
Find the Nth element of the Iterable<> | |
nonvirtual T | NthValue (ptrdiff_t n, ArgByValueType< T > defaultValue={}) const |
Find the Nth element of the Iterable<>, but allow for n to be out of range, and just return argument default-value. | |
template<derived_from< Iterable< T > > RESULT_CONTAINER = Iterable<T>, predicate< T > INCLUDE_PREDICATE> | |
nonvirtual RESULT_CONTAINER | Where (INCLUDE_PREDICATE &&includeIfTrue) const |
produce a subset of this iterable where argument function returns true | |
template<Common::IPotentiallyComparer< T > EQUALS_COMPARER = equal_to<T>> | |
nonvirtual Iterable< T > | Distinct (EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{}) const |
template<ranges::range RESULT_CONTAINER = Iterable<T>, invocable< T > ELEMENT_MAPPER> requires (convertible_to<invoke_result_t<ELEMENT_MAPPER, T>, typename RESULT_CONTAINER::value_type> or convertible_to<invoke_result_t<ELEMENT_MAPPER, T>, optional<typename RESULT_CONTAINER::value_type>>) | |
nonvirtual RESULT_CONTAINER | Map (ELEMENT_MAPPER &&elementMapper) const |
functional API which iterates over all members of an Iterable, applies a map function to each element, and collects the results in a new Iterable | |
template<typename REDUCED_TYPE = T> | |
nonvirtual optional< REDUCED_TYPE > | Reduce (const function< REDUCED_TYPE(ArgByValueType< T >, ArgByValueType< T >)> &op) const |
Walk the entire list of items, and use the argument 'op' to combine (reduce) items to a resulting single item. | |
template<typename REDUCED_TYPE = T> | |
nonvirtual REDUCED_TYPE | ReduceValue (const function< REDUCED_TYPE(ArgByValueType< T >, ArgByValueType< T >)> &op, ArgByValueType< REDUCED_TYPE > defaultValue={}) const |
template<typename RESULT_T = Characters::String, invocable< T > CONVERT_TO_RESULT = decltype (kDefaultToStringConverter<>), invocable< RESULT_T, RESULT_T, bool > COMBINER = decltype (Characters::kDefaultStringCombiner)> requires (convertible_to<invoke_result_t<CONVERT_TO_RESULT, T>, RESULT_T> and convertible_to<invoke_result_t<COMBINER, RESULT_T, RESULT_T, bool>, RESULT_T>) | |
nonvirtual RESULT_T | Join (const CONVERT_TO_RESULT &convertToResult=kDefaultToStringConverter<>, const COMBINER &combiner=Characters::kDefaultStringCombiner) const |
ape the JavaScript/python 'join' function - take the parts of 'this' iterable and combine them into a new object (typically a string) | |
nonvirtual Iterable< T > | Skip (size_t nItems) const |
nonvirtual Iterable< T > | Take (size_t nItems) const |
nonvirtual Iterable< T > | Slice (size_t from, size_t to) const |
nonvirtual Iterable< T > | Top () const |
return the top/largest (possibly just top N) values from this Iterable<T> | |
template<Common::IPotentiallyComparer< T > INORDER_COMPARER_TYPE = less<T>> | |
nonvirtual Iterable< T > | OrderBy (INORDER_COMPARER_TYPE &&inorderComparer=INORDER_COMPARER_TYPE{}, Execution::SequencePolicy seq=Execution::SequencePolicy::ePar) const |
template<Common::IPotentiallyComparer< T > INORDER_COMPARER_TYPE = less<T>> | |
nonvirtual bool | IsOrderedBy (INORDER_COMPARER_TYPE &&inorderComparer=INORDER_COMPARER_TYPE{}) const |
nonvirtual optional< T > | First () const |
return first element in iterable, or if 'that' specified, first where 'that' is true, (or return nullopt if none) | |
nonvirtual T | FirstValue (ArgByValueType< T > defaultValue={}) const |
return first element in iterable provided default | |
nonvirtual optional< T > | Last () const |
return last element in iterable, or if 'that' specified, last where 'that' is true, (or return missing) | |
nonvirtual T | LastValue (ArgByValueType< T > defaultValue={}) const |
nonvirtual bool | All (const function< bool(ArgByValueType< T >)> &testEachElt) const |
return true iff argument predicate returns true for each element of the iterable | |
nonvirtual optional< T > | Min () const |
template<typename RESULT_TYPE = T> | |
nonvirtual RESULT_TYPE | MinValue (ArgByValueType< RESULT_TYPE > defaultValue={}) const |
nonvirtual optional< T > | Max () const |
template<typename RESULT_TYPE = T> | |
nonvirtual RESULT_TYPE | MaxValue (ArgByValueType< RESULT_TYPE > defaultValue={}) const |
template<typename RESULT_TYPE = T> | |
nonvirtual optional< RESULT_TYPE > | Mean () const |
template<typename RESULT_TYPE = T> | |
nonvirtual RESULT_TYPE | MeanValue (ArgByValueType< RESULT_TYPE > defaultValue={}) const |
template<typename RESULT_TYPE = T> | |
nonvirtual optional< RESULT_TYPE > | Sum () const |
template<typename RESULT_TYPE = T> | |
nonvirtual RESULT_TYPE | SumValue (ArgByValueType< RESULT_TYPE > defaultValue={}) const |
template<constructible_from< T > RESULT_TYPE = T, Common::IPotentiallyComparer< RESULT_TYPE > INORDER_COMPARE_FUNCTION = less<RESULT_TYPE>> | |
nonvirtual optional< RESULT_TYPE > | Median (const INORDER_COMPARE_FUNCTION &compare={}) const |
template<constructible_from< T > RESULT_TYPE = T> | |
nonvirtual RESULT_TYPE | MedianValue (ArgByValueType< RESULT_TYPE > defaultValue={}) const |
nonvirtual Iterable< T > | Repeat (size_t count) const |
nonvirtual bool | Any () const |
Any() same as not empty (); Any (includeIfTrue) returns true iff includeIfTrue returns true on any values in iterable. | |
nonvirtual size_t | Count () const |
with no args, same as size, with function filter arg, returns number of items that pass. | |
nonvirtual size_t | length () const |
STL-ish alias for size() - really in STL only used in string, I think, but still makes sense as an alias. | |
Protected Member Functions | |
nonvirtual tuple< _IRep *, Iterator< value_type > > | _GetWritableRepAndPatchAssociatedIterator (const Iterator< value_type > &i) |
Utility to get WRITABLE underlying shared_ptr (replacement for what we normally do - _SafeReadWriteRepAccessor<_IRep>{this}._GetWriteableRep ()) but where we also handle the cloning/patching of the associated iterator. | |
![]() | |
Iterable (const shared_ptr< _IRep > &rep) noexcept | |
Iterable's are typically constructed as concrete subtype objects, whose CTOR passed in a shared copyable rep. | |
nonvirtual Memory::SharedByValue_State | _GetSharingState () const |
Additional Inherited Members | |
![]() | |
template<ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer< T > EQUALS_COMPARER = equal_to<T>> | |
static bool | SetEquals (const LHS_CONTAINER_TYPE &lhs, const RHS_CONTAINER_TYPE &rhs, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{}) |
template<ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer< T > EQUALS_COMPARER = equal_to<T>> | |
static bool | MultiSetEquals (const LHS_CONTAINER_TYPE &lhs, const RHS_CONTAINER_TYPE &rhs, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{}) |
template<ranges::range LHS_CONTAINER_TYPE, ranges::range RHS_CONTAINER_TYPE, IEqualsComparer< T > EQUALS_COMPARER = equal_to<T>> | |
static bool | SequentialEquals (const LHS_CONTAINER_TYPE &lhs, const RHS_CONTAINER_TYPE &rhs, EQUALS_COMPARER &&equalsComparer=EQUALS_COMPARER{}, bool useIterableSize=false) |
static constexpr default_sentinel_t | end () noexcept |
Support for ranged for, and STL syntax in general. | |
![]() | |
template<same_as< Characters::String > RESULT_T = Characters::String> | |
static const function< RESULT_T(T)> | kDefaultToStringConverter |
![]() | |
using | _SharedByValueRepType = Memory::SharedByValue< _IRep, Memory::SharedByValue_Traits< _IRep, shared_ptr< _IRep >, Rep_Cloner_ > > |
Lazy-copying smart pointer mostly used by implementors (can generally be ignored by users). However, protected because manipulation needed in some subclasses (rarely) - like UpdatableIteratable. | |
![]() | |
_SharedByValueRepType | _fRep |
Mapping which allows for the association of two elements: a key and
a value. The key UNIQUELY specifies its associated value.
Concrete Implementations: o
Factory:
Design Note: Included <map> and have explicit CTOR for map<> so that Stroika Mapping can be used more interoperably with map<> - and used without an explicit CTOR. Use Explicit CTOR to avoid accidental conversions. But if you declare an API with Mapping<KEY_TYPE,MAPPED_VALUE_TYPE> arguments, its important STL sources passing in map<> work transparently.
Similarly for std::initializer_list.
Two Mappings are considered equal if they contain the same elements (keys) and each key is associated with the same value. There is no need for the items to appear in the same order for the two Mappings to be equal. There is no need for the backends to be of the same underlying representation either (stl map vers linked list). \pre lhs and rhs arguments must have the same (or equivalent) EqualsComparers. @todo - document computational complexity ThreeWayComparer support is NOT provided for Mapping, because there is no intrinsic ordering among the elements of the mapping (keys) - even if there was some way to compare the values.
using Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::ArchetypeContainerType = Mapping |
using Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::value_type = typename inherited::value_type |
using Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::key_type = KEY_TYPE |
using Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::mapped_type = MAPPED_VALUE_TYPE |
using Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::KeyEqualsCompareFunctionType = Common::ComparisonRelationDeclaration<Common::ComparisonRelationType::eEquals, function<bool (ArgByValueType<key_type>, ArgByValueType<key_type>)> > |
Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::Mapping | ( | ) |
This constructor creates a concrete mapping object, either empty, or initialized with any argument values.
The underlying data structure (and performance characteristics) of the Mapping is defined by
Definition at line 25 of file Mapping.inl.
Iterable< KEY_TYPE > Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::Keys | ( | ) | const |
Keys () returns an Iterable object with just the key part of the Mapping.
It is equivalent to copying the underlying Mapping and 'projecting' the key fields (so the result will be sorted in a SortedMapping).
This means that Keys() is detached from the original Mapping (should that change) and its lifetime may extend past the lifetime of the original mapping.
Design Note: The analogous method in C#.net - Dictionary<TKey, TValue>.KeyCollection (http://msdn.microsoft.com/en-us/library/yt2fy5zk(v=vs.110).aspx) returns a live reference to the underlying keys. We could have (fairly easily) done that, but I didn't see the point.
In .net, the typical model is that you have a pointer to an object, and pass around that pointer (so by reference semantics) - so this returning a live reference makes more sense there.
Since Stroika containers are logically copy-by-value (even though lazy-copied), it made more sense to apply that lazy-copy (copy-on-write) paradigm here, and make the returned set of keys a logical copy at the point 'keys' is called.
See:
Definition at line 113 of file Mapping.inl.
Iterable< MAPPED_VALUE_TYPE > Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::MappedValues | ( | ) | const |
MappedValues () returns an Iterable object with just the value part of the Mapping.
It is equivalent to copying the underlying collection and 'projecting' the value fields.
This means that Keys() is detached from the original Mapping (should that change) and its lifetime may extend past the lifetime of the original mapping.
Design Note: The analogous method in C#.net - Dictionary<TKey, TValue>.ValueCollection (https://msdn.microsoft.com/en-us/library/x8bctb9c%28v=vs.110%29.aspx).aspx) returns a live reference to the underlying keys. We could have (fairly easily) done that, but I didn't see the point.
In .net, the typical model is that you have a pointer to an object, and pass around that pointer (so by reference semantics) - so this returning a live reference makes more sense there.
Since Stroika containers are logically copy-by-value (even though lazy-copied), it made more sense to apply that lazy-copy (copy-on-write) paradigm here, and make the returned set of keys a logical copy at the point 'keys' is called.
See:
Definition at line 118 of file Mapping.inl.
optional< MAPPED_VALUE_TYPE > Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::Lookup | ( | ArgByValueType< key_type > | key | ) | const |
Note - as since Lookup/1 returns an optional<T> - it can be used very easily to provide a default value on Lookup (so for case where not present) - as in: return m.Lookup (key).Value (putDefaultValueHere);
Note - for both overloads taking an item pointer, the pointer may be nullptr (in which case not assigned to). But if present, will always be assigned to if Lookup returns true (found). And for the optional overload
@todo http://stroika-bugs.sophists.com/browse/STK-928 - add overload 'returning' Iterator<>, so can use with Update method
Definition at line 144 of file Mapping.inl.
nonvirtual mapped_type Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::LookupChecked | ( | ArgByValueType< key_type > | key, |
const THROW_IF_MISSING & | throwIfMissing | ||
) | const |
MAPPED_VALUE_TYPE Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::LookupValue | ( | ArgByValueType< key_type > | key, |
ArgByValueType< mapped_type > | defaultValue = mapped_type{} |
||
) | const |
Always safe to call. If result of Lookup () !has_value, returns argument 'default' or 'sentinel' value.
Definition at line 168 of file Mapping.inl.
auto Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::operator[] | ( | ArgByValueType< key_type > | key | ) | const |
Defined operator[](KEY_TYPE) const - to return MAPPED_VALUE_TYPE instead of MAPPED_VALUE_TYPE& because we then couldn't control the lifetime of that reference, and it would be unsafe as the underlying object was changed.
And therefore we return CONST of that type so that code like m["xx"].a = 3 won't compile (and wont just assign to a temporary that disappears leading to confusion).
Definition at line 174 of file Mapping.inl.
bool Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::ContainsKey | ( | ArgByValueType< key_type > | key | ) | const |
Synonym for Lookup (key).has_value ()
Definition at line 179 of file Mapping.inl.
nonvirtual bool Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::ContainsMappedValue | ( | ArgByValueType< mapped_type > | v, |
VALUE_EQUALS_COMPARER && | valueEqualsComparer = {} |
||
) | const |
Likely inefficient for a map, but perhaps helpful. Walks entire list of entires and applies VALUE_EQUALS_COMPARER (defaults to operator==) on each value, and returns true if contained. Perhaps not very useful but symmetric to ContainsKey().
bool Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::Add | ( | ArgByValueType< key_type > | key, |
ArgByValueType< mapped_type > | newElt, | ||
AddReplaceMode | addReplaceMode = AddReplaceMode::eAddReplaces |
||
) |
Add the association between key and newElt.
If key was already associated with something, consult argument addReplaceMode (defaults to AddReplaceMode::eAddReplaces). if 'replaces' then replace, and if 'addif' then do nothing on Add ()
Also - we guarantee that even if the association is different, if the key has not changed, then the iteration order is not changed (helpful for AddAll() semantics, and perhaps elsewhere).
Definition at line 190 of file Mapping.inl.
nonvirtual unsigned int Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::AddAll | ( | ITERABLE_OF_ADDABLE && | items, |
AddReplaceMode | addReplaceMode = AddReplaceMode::eAddReplaces |
||
) |
\summary Add all the argument (container or bound range of iterators) elements; if replaceExistingMapping true (default) force replace on each. Return count of added items (not count of updated items)
void Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::Remove | ( | ArgByValueType< key_type > | key | ) |
Remove the given item (which must exist).
nextI | - if provided (not null) - will be filled in with the next value after where iterator i is pointing - since i is invalidated by changing the container) |
Definition at line 225 of file Mapping.inl.
bool Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::RemoveIf | ( | ArgByValueType< key_type > | key | ) |
Remove the given item, if it exists. Return true if found and removed.
Definition at line 237 of file Mapping.inl.
void Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::RemoveAll | ( | ) |
RemoveAll removes all, or all matching (predicate, iterator range, equals comparer or whatever) items.
The no-arg overload removes all (quickly).
The overloads that remove some subset of the items returns the number of items so removed, and use RemoveIf() so that the argument items designated to be removed MAY not be present.
Definition at line 242 of file Mapping.inl.
void Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::Update | ( | const Iterator< value_type > & | i, |
ArgByValueType< mapped_type > | newValue, | ||
Iterator< value_type > * | nextI = nullptr |
||
) |
Update the value associated with the iterator 'i', without changing iteration order in any way (cuz the key not changed). Note - if iterating, because this modifies the underlying container, the caller should pass 'i' in as a reference parameter to 'nextI' to have it updated to safely continue iterating.
Definition at line 312 of file Mapping.inl.
nonvirtual void Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::RetainAll | ( | const ITERABLE_OF_KEY_TYPE & | items | ) |
Remove all items from this container UNLESS they are in the argument set to RetainAll().
This restricts the 'Keys' list of Mapping to the argument data, but preserving any associations.
nonvirtual RESULT_CONTAINER Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::Where | ( | INCLUDE_PREDICATE && | includeIfTrue | ) | const |
Apply the function function to each element, and return a subset Mapping including just the ones for which it was true.
nonvirtual ArchetypeContainerType Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::WithKeys | ( | const CONTAINER_OF_KEYS & | includeKeys | ) | const |
Return a subset of this Mapping<> where the keys are included in the argument includeKeys set..
nonvirtual CONTAINER_OF_Key_T Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::As | ( | ) | const |
This function should work for any container which accepts (ITERATOR_OF<KeyValuePair<Key,Value>>,ITERATOR_OF<KeyValuePair<Key,Value>>) OR (ITERATOR_OF<pair<Key,Value>>,ITERATOR_OF<pair<Key,Value>>).
These As<> overloads also may require the presence of an insert(ITERATOR, Value) method of CONTAINER_OF_Key_T.
So - for example, Sequence<KeyValuePair<key_type,ValueType>>, map<key_type,ValueType>, vector<pair<key_type,ValueType>>, etc...
|
protected |
Utility to get WRITABLE underlying shared_ptr (replacement for what we normally do - _SafeReadWriteRepAccessor<_IRep>{this}._GetWriteableRep ()) but where we also handle the cloning/patching of the associated iterator.
When you have a non-const operation (such as Remove) with an argument of an Iterator<>, then due to COW, you may end up cloning the container rep, and yet the Iterator<> contains a pointer to the earlier rep (and so maybe unusable).
Prior to Stroika 2.1b14, this was handled elegantly, and automatically, by the iterator patching mechanism. But that was deprecated (due to cost, and rarity of use), in favor of this more restricted feature, where we just patch the iterators on an as-needed basis.
Definition at line 470 of file Mapping.inl.
bool Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::operator== | ( | const Mapping< KEY_TYPE, MAPPED_VALUE_TYPE > & | rhs | ) | const |
compares if the two mappings have the same keys, and corresponding values (doesn't check ordering same). Note this can be costly, as the Mappings are not necessarily in the same order
simply indirect to @Mapping<>::EqualsComparer; only defined if there is a default equals comparer for mapped_type
Definition at line 490 of file Mapping.inl.
void Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::Accumulate | ( | ArgByValueType< key_type > | key, |
ArgByValueType< mapped_type > | newValue, | ||
const function< mapped_type(ArgByValueType< mapped_type >, ArgByValueType< mapped_type >)> & | f = [] (ArgByValueType<mapped_type> l, ArgByValueType<mapped_type> r) -> mapped_type { return l + r; } , |
||
mapped_type | initialValue = {} |
||
) |
like Add (key, newValue) - BUT newValue is COMBINED with the 'f' argument.
The accumulator function combines the previous value associated with the new value given (using initialValue if key was not already present in the map).
Definition at line 419 of file Mapping.inl.
void Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::insert | ( | ArgByValueType< value_type > | kvp | ) |
Definition at line 426 of file Mapping.inl.
void Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::erase | ( | ArgByValueType< key_type > | key | ) |
Definition at line 431 of file Mapping.inl.
void Stroika::Foundation::Containers::Mapping< KEY_TYPE, MAPPED_VALUE_TYPE >::clear | ( | ) |
Definition at line 443 of file Mapping.inl.