An Association pairs key values with (possibly multiple or none) mapped_type values. Like Mapping<>, but allowing multiple items associated with 'key'. More...
#include <Association.h>
Classes | |
class | _IRep |
Implementation detail for Association<T> implementors. More... | |
struct | EqualsComparer |
Compare Associations<>s for equality. More... | |
Public Types | |
using | ArchetypeContainerType = Association |
using | value_type = typename inherited::value_type |
using | key_type = KEY_TYPE |
using | mapped_type = MAPPED_VALUE_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 | |
Association () | |
nonvirtual Iterable< key_type > | Keys () const |
nonvirtual Iterable< mapped_type > | MappedValues () const |
nonvirtual Traversal::Iterable< mapped_type > | Lookup (ArgByValueType< key_type > key) const |
Return an Iterable<mapped_type> of all the associated items (can be empty if none). This iterable is a snapshot at the time of call (but maybe lazy COW copied snapshot so still cheap) | |
nonvirtual optional< mapped_type > | LookupOne (ArgByValueType< key_type > key) const |
Lookup and return the first (maybe arbitrarily chosen which is first) value with this key, and throw if there are none. | |
template<typename THROW_IF_MISSING > | |
nonvirtual mapped_type | LookupOneChecked (ArgByValueType< key_type > key, const THROW_IF_MISSING &throwIfMissing) const |
Lookup and return the first (maybe arbitrarily chosen which is first) value with this key, and throw if there are none. | |
nonvirtual mapped_type | LookupOneValue (ArgByValueType< key_type > key, ArgByValueType< mapped_type > defaultValue=mapped_type{}) const |
Lookup and return the first (maybe arbitrarily chosen which is first) value with this key, and otherwise return argument value as default. | |
nonvirtual const Iterable< mapped_type > | operator[] (ArgByValueType< key_type > key) const |
Shortcut for Lookup. | |
nonvirtual bool | ContainsKey (ArgByValueType< key_type > key) const |
nonvirtual size_t | OccurrencesOf (ArgByValueType< key_type > item) const |
template<Common::IEqualsComparer< MAPPED_VALUE_TYPE > VALUE_EQUALS_COMPARER = equal_to<MAPPED_VALUE_TYPE>> | |
nonvirtual bool | ContainsMappedValue (ArgByValueType< mapped_type > v, const VALUE_EQUALS_COMPARER &valueEqualsComparer={}) const |
nonvirtual void | Add (ArgByValueType< key_type > key, ArgByValueType< mapped_type > newElt) |
template<IIterableOfTo< KeyValuePair< KEY_TYPE, MAPPED_VALUE_TYPE > > ITERABLE_OF_ADDABLE> | |
nonvirtual void | AddAll (ITERABLE_OF_ADDABLE &&items) |
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 = Association<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 RESULT_CONTAINER defaults to Association, and improve that case to clone properties from this rep (such is rep type, comparisons etc). | |
template<derived_from< Iterable< KeyValuePair< KEY_TYPE, MAPPED_VALUE_TYPE > > > RESULT_CONTAINER = Association<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 Association &rhs) const |
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 | erase (ArgByValueType< key_type > key) |
STL-ish alias for Remove (). | |
nonvirtual void | clear () |
STL-ish alias for RemoveAll (). | |
![]() | |
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 |
An Association pairs key values with (possibly multiple or none) mapped_type values. Like Mapping<>, but allowing multiple items associated with 'key'.
Association which allows for the association of two elements: a key and
a value. Unlike a Mapping<>, this association may not be unique..
Concrete Implementations: o
Factory:
Design Note: Included <map> and have explicit CTOR for multimap<> so that Stroika Association can be used more interoperably with multimap<> - and used without an explicit CTOR. Use Explicit CTOR to avoid accidental conversions. But if you declare an API with Association<KEY_TYPE,MAPPED_VALUE_TYPE> arguments, its important STL sources passing in multimap<> work transparently.
Similarly for std::initializer_list.
Two Associations 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 Associations to be equal. There is no need for the backends to be of the same underlying representation either (stlmap vers LinkedList). \pre lhs and rhs arguments must have the same (or equivalent) EqualsComparers. @todo - document computational complexity ThreeWayComparer support is NOT provided for Association, because there is no intrinsic ordering among the elements of the Association (keys) - even if there was some way to compare the values.
Definition at line 113 of file Association.h.
using Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::ArchetypeContainerType = Association |
Use this typedef in templates to recover the basic functional container pattern of concrete types.
Definition at line 124 of file Association.h.
using Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::value_type = typename inherited::value_type |
Definition at line 130 of file Association.h.
using Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::key_type = KEY_TYPE |
like std::multimap<>::key_type
Definition at line 136 of file Association.h.
using Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::mapped_type = MAPPED_VALUE_TYPE |
like std::multimap<>::mapped_type
Definition at line 142 of file Association.h.
Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::Association | ( | ) |
This constructor creates a concrete Association object, either empty, or initialized with any argument values.
The underlying data structure (and performance characteristics) of the Association is defined by
Definition at line 25 of file Association.inl.
Iterable< KEY_TYPE > Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::Keys | ( | ) | const |
Keys () returns an Iterable object with just the key part of the Association.
It is equivalent to copying the underlying collection and 'projecting' the key fields.
Note the returned Iterable is detached from the original, and doesn't see any changes to it, and its lifetime is like a copy of a shared_ptr - lasts as long as the reference.
Design Note: The analagous 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 Association.inl.
Iterable< MAPPED_VALUE_TYPE > Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::MappedValues | ( | ) | const |
MappedValues () returns an Iterable object with just the value part of the Association.
It is equivalent to copying the underlying collection and 'projecting' the value fields.
Note the returned Iterable is detached from the original, and doesn't see any changes to it, and its lifetime is like a copy of a shared_ptr - lasts as long as the reference.
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 Association.inl.
optional< MAPPED_VALUE_TYPE > Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::LookupOne | ( | ArgByValueType< key_type > | key | ) | const |
Lookup and return the first (maybe arbitrarily chosen which is first) value with this key, and throw if there are none.
Definition at line 128 of file Association.inl.
nonvirtual mapped_type Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::LookupOneChecked | ( | ArgByValueType< key_type > | key, |
const THROW_IF_MISSING & | throwIfMissing | ||
) | const |
Lookup and return the first (maybe arbitrarily chosen which is first) value with this key, and throw if there are none.
MAPPED_VALUE_TYPE Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::LookupOneValue | ( | ArgByValueType< key_type > | key, |
ArgByValueType< mapped_type > | defaultValue = mapped_type{} |
||
) | const |
Lookup and return the first (maybe arbitrarily chosen which is first) value with this key, and otherwise return argument value as default.
Definition at line 148 of file Association.inl.
auto Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::operator[] | ( | ArgByValueType< key_type > | key | ) | const |
Shortcut for Lookup.
if key is not in the container, an empty iterable will be returned.
Definition at line 158 of file Association.inl.
bool Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::ContainsKey | ( | ArgByValueType< key_type > | key | ) | const |
Synonym for Lookup (key).has_value ()
Definition at line 163 of file Association.inl.
size_t Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::OccurrencesOf | ( | ArgByValueType< key_type > | item | ) | const |
OccurrencesOf() returns the number of occurrences of 'item' in the association.
Definition at line 168 of file Association.inl.
nonvirtual bool Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::ContainsMappedValue | ( | ArgByValueType< mapped_type > | v, |
const VALUE_EQUALS_COMPARER & | valueEqualsComparer = {} |
||
) | const |
Likely inefficient, 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().
void Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::Add | ( | ArgByValueType< key_type > | key, |
ArgByValueType< mapped_type > | newElt | ||
) |
Add the association between key and newElt. Note, this increases teh size of the container by one, even if key was already present in the association.
Definition at line 180 of file Association.inl.
nonvirtual void Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::AddAll | ( | ITERABLE_OF_ADDABLE && | items | ) |
\summary Add all the argument (container or bound range of iterators) elements.
void Stroika::Foundation::Containers::Association< 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 212 of file Association.inl.
bool Stroika::Foundation::Containers::Association< 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 224 of file Association.inl.
void Stroika::Foundation::Containers::Association< 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 229 of file Association.inl.
void Stroika::Foundation::Containers::Association< 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 299 of file Association.inl.
nonvirtual void Stroika::Foundation::Containers::Association< 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 Association to the argument data, but preserving any associations.
nonvirtual RESULT_CONTAINER Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::Where | ( | INCLUDE_PREDICATE && | includeIfTrue | ) | const |
Apply the function function to each element, and return a subset Association including just the ones for which it was true.
nonvirtual ArchetypeContainerType Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::WithKeys | ( | const CONTAINER_OF_KEYS & | includeKeys | ) | const |
Return a subset of this Association<> where the keys are included in the argument includeKeys set..
nonvirtual CONTAINER_OF_Key_T Stroika::Foundation::Containers::Association< 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 448 of file Association.inl.
bool Stroika::Foundation::Containers::Association< KEY_TYPE, MAPPED_VALUE_TYPE >::operator== | ( | const Association< KEY_TYPE, MAPPED_VALUE_TYPE > & | rhs | ) | const |
simply indirect to @Association<>::EqualsComparer; only defined if there is a default equals comparer for mapped_type
Definition at line 468 of file Association.inl.
void Stroika::Foundation::Containers::Association< 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 402 of file Association.inl.