#include <hybridmap.h>
A HybridMap allows to take advantage of two different map implementations. For example, in a typical setting an ArrayMap may perform better with a low number of entries, while a BurstTrieMap gets better when the number of entries increases. If you cannot predict that the number of entries will always be small (to use an ArrayMap) or large (to use a BurstTrieMap), you can use the HybridMap which automatically switches between two implementations based on the number of entries:
See HashMap for more examples on how to use maps in general.
K | Type of keys. |
V | Type of values. |
SMALL | A map selector template to choose the map implementation to use for a small number of entries. |
LARGE | A map selector template to choose the map implementation to use for a large number of entries. |
THRESHOLD | When the number of entries reaches THRESHOLD, HybridMap switches to the LARGE implementation. |
REVERSE_THRESHOLD | When the number of entries falls below REVERSE_THRESHOLD, HybridMap switches back to the SMALL implementation. If this is negative, this will never happen. |
Classes | |
class | EntryIteratorBase |
class | IteratorBase |
class | IteratorTemplate |
class | KeyIteratorBase |
class | NonConstIteratorBase |
class | ValueIteratorBase |
Public Types | |
using | SmallType = typename SMALL::template Type< K, V > |
using | LargeType = typename LARGE::template Type< K, V > |
using | IsHybridMap = std::true_type |
using | Iterator = IteratorTemplate< false, EntryIteratorBase > |
using | ConstIterator = IteratorTemplate< true, EntryIteratorBase > |
using | KeyIterator = IteratorTemplate< false, KeyIteratorBase > |
using | ConstKeyIterator = IteratorTemplate< true, KeyIteratorBase > |
using | ValueIterator = IteratorTemplate< false, ValueIteratorBase > |
using | ConstValueIterator = IteratorTemplate< true, ValueIteratorBase > |
Public Types inherited from MapBase0< COLLECTION, KEYTYPE, VALUETYPE, SUPER, HASH > | |
using | MapType = COLLECTION |
using | Super = BaseCollection< COLLECTION, SUPER > |
using | KeyType = KEYTYPE |
using | ValueType = VALUETYPE |
Public Types inherited from BaseCollection< COLLECTION, SUPER > | |
using | IsCollection = std::true_type |
using | IsBaseArray = std::false_type |
Public Member Functions | |
Iterator | Begin () |
Iterator | End () |
ConstIterator | Begin () const |
ConstIterator | End () const |
KeyIterator | GetKeys () |
ConstKeyIterator | GetKeys () const |
ValueIterator | GetValues () |
ConstValueIterator | GetValues () const |
HybridMap () | |
~HybridMap () | |
HybridMap (HybridMap &&src) | |
MAXON_OPERATOR_MOVE_ASSIGNMENT (HybridMap) | |
template<typename MAP > | |
Result< void > | CopyFromImpl (MAP &&src, COLLECTION_RESIZE_FLAGS resizeFlags, OverloadRank0) |
template<typename MAP > | |
SFINAEHelper< Result< void >, typename std::remove_reference< MAP >::type::IsHybridMap >::type | CopyFromImpl (MAP &&src, COLLECTION_RESIZE_FLAGS resizeFlags, OverloadRank1) |
void | Flush () |
void | Reset () |
Int | GetCount () const |
Int | GetOperationCountForSearch () const |
Int | GetMemorySize () const |
ResultMem | SetCapacityHint (Int capacity, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY) |
ResultRef< V > | InsertKey (const K &key, Bool &created=BoolLValue()) |
ResultRef< V > | InsertKey (K &&key, Bool &created=BoolLValue()) |
ResultMemT< Iterator > | InsertEntry (const K &key, Bool &created=BoolLValue()) |
ResultMemT< Iterator > | InsertEntry (K &&key, Bool &created=BoolLValue()) |
ResultMemT< Iterator > | Insert (const K &key, const V &value, Bool &created=BoolLValue()) |
ResultMemT< Iterator > | Insert (K &&key, const V &value, Bool &created=BoolLValue()) |
ResultMemT< Iterator > | Insert (const K &key, V &&value, Bool &created=BoolLValue()) |
ResultMemT< Iterator > | Insert (K &&key, V &&value, Bool &created=BoolLValue()) |
template<typename KEY = K> | |
const V * | FindValue (const KEY &key) const |
template<typename KEY = K> | |
V * | FindValue (const KEY &key) |
template<typename KEY = K> | |
Iterator | Find (const KEY &key) |
template<typename KEY = K> | |
ConstIterator | Find (const KEY &key) const |
template<typename KEY = K> | |
Iterator | FindFloor (const KEY &key) |
template<typename KEY = K> | |
ConstIterator | FindFloor (const KEY &key) const |
Result< Bool > | Erase (const K &key) |
template<template< Bool > class SUPER> | |
IteratorTemplate< false, SUPER > | Erase (const IteratorTemplate< false, SUPER > &position) |
Result< void > | UseLargeMap () |
Result< void > | UseSmallMap () |
Public Member Functions inherited from MapBase< HybridMap< K, V, SMALL, LARGE, THRESHOLD, REVERSE_THRESHOLD >, K, V, EmptyClass, DefaultCompare > | |
MAXON_ATTRIBUTE_FORCE_INLINE | MapBase (ARGS &&... args) |
MapImpl< HybridMap< K, V, SMALL, LARGE, THRESHOLD, REVERSE_THRESHOLD > & > | ToMap () |
MapImpl< const HybridMap< K, V, SMALL, LARGE, THRESHOLD, REVERSE_THRESHOLD > & > | ToMap () const |
MAXON_ATTRIBUTE_FORCE_INLINE | operator MapImpl< HybridMap< K, V, SMALL, LARGE, THRESHOLD, REVERSE_THRESHOLD > & > () |
MAXON_ATTRIBUTE_FORCE_INLINE | operator MapImpl< const HybridMap< K, V, SMALL, LARGE, THRESHOLD, REVERSE_THRESHOLD > & > () const |
Public Member Functions inherited from MapBase0< COLLECTION, KEYTYPE, VALUETYPE, SUPER, HASH > | |
template<typename... ARGS> | |
MAXON_ATTRIBUTE_FORCE_INLINE | MapBase0 (ARGS &&... args) |
MAXON_ATTRIBUTE_FORCE_INLINE Bool | Contains (typename ByValueParam< KEYTYPE >::type key) const |
template<typename PAIR > | |
MAXON_ATTRIBUTE_FORCE_INLINE SFINAEHelper< Bool, typename PAIR::KeyType >::type | Contains (const PAIR &pair) const |
ResultRef< VALUETYPE > | Append (const KEYTYPE &key) |
template<typename PAIR > | |
SFINAEHelper< ResultRef< VALUETYPE >, typename PAIR::KeyType >::type | Append (const PAIR &pair) |
template<typename COLLECTION2 > | |
Result< void > | Add (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY) |
template<typename COLLECTION2 > | |
Result< void > | AppendAll (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY) |
template<typename COLLECTION2 > | |
Result< void > | AppendAllInverse (COLLECTION2 &&other) |
template<typename COLLECTION2 > | |
Bool | ContainsAllImpl (COLLECTION2 &&other, OverloadRank0) const |
template<typename COLLECTION2 > | |
Result< void > | SubtractImpl (COLLECTION2 &&other, OverloadRank0) |
template<typename COLLECTION2 , typename COMPARE > | |
Bool | IsEqualImpl (const COLLECTION2 &other, COMPARE &&cmp, OverloadRank0) const |
HashInt | GetHashCode () const |
UniqueHash | GetUniqueHashCode () const |
Public Member Functions inherited from BaseCollection< COLLECTION, SUPER > | |
template<typename... ARGS> | |
MAXON_ATTRIBUTE_FORCE_INLINE | BaseCollection (ARGS &&... args) |
template<typename COLLECTION2 > | |
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value, Bool >::type | operator== (const COLLECTION2 &other) const |
template<typename COLLECTION2 > | |
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value, Bool >::type | operator!= (const COLLECTION2 &other) const |
template<typename COMPARE = EqualityCompare, typename COLLECTION2 > | |
MAXON_ATTRIBUTE_FORCE_INLINE std::enable_if< maxon::IsCollection< COLLECTION2 >::value &&!STD_IS_REPLACEMENT(same, typename std::decay< COMPARE >::type, EQUALITY), Bool >::type | IsEqual (const COLLECTION2 &other, COMPARE &&cmp=COMPARE()) const |
template<typename COLLECTION2 > | |
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > | AppendAll (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY) |
template<typename COLLECTION2 > | |
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > | CopyFrom (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags=COLLECTION_RESIZE_FLAGS::FIT_TO_SIZE) |
template<typename COLLECTION2 > | |
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > | Subtract (COLLECTION2 &&other) |
template<typename COLLECTION2 > | |
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > | Intersect (const COLLECTION2 &other) |
template<typename COLLECTION2 > | |
Bool | Intersects (const COLLECTION2 &other) const |
template<typename COLLECTION2 > | |
MAXON_ATTRIBUTE_FORCE_INLINE Result< void > | CopyFromImpl (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags, OverloadRank0) |
template<typename COLLECTION2 > | |
Result< void > | AppendAllImpl (COLLECTION2 &&other, COLLECTION_RESIZE_FLAGS resizeFlags, Bool overwrite, OverloadRank0) |
template<typename COLLECTION2 > | |
Result< void > | IntersectImpl (COLLECTION2 &&other, OverloadRank0) |
MAXON_ATTRIBUTE_FORCE_INLINE Bool | IsEmpty () const |
MAXON_ATTRIBUTE_FORCE_INLINE Bool | IsPopulated () const |
String | ToString (const FormatStatement *formatStatement=nullptr) const |
template<typename COLLECTION2 > | |
MAXON_ATTRIBUTE_FORCE_INLINE Bool | ContainsAll (COLLECTION2 &&other) const |
template<typename COLLECTION2 > | |
Bool | ContainsAllImpl (COLLECTION2 &&other, OverloadRank0) const |
Protected Member Functions | |
SmallType & | GetSmall () |
LargeType & | GetLarge () |
const SmallType & | GetSmall () const |
const LargeType & | GetLarge () const |
Protected Attributes | |
Bool | _small |
std::aligned_union< 0, SmallType, LargeType >::type | _union [1] |
Private Member Functions | |
MAXON_DISALLOW_COPY_AND_ASSIGN (HybridMap) | |
Additional Inherited Members | |
Static Public Member Functions inherited from MapBase0< COLLECTION, KEYTYPE, VALUETYPE, SUPER, HASH > | |
static const KEYTYPE & | GetMapKey (const KEYTYPE &key) |
template<typename PAIR > | |
static const KEYTYPE & | GetMapKey (const PAIR &pair) |
Static Public Attributes inherited from MapBase0< COLLECTION, KEYTYPE, VALUETYPE, SUPER, HASH > | |
static const COLLECTION_KIND | KIND |
using SmallType = typename SMALL::template Type<K, V> |
using LargeType = typename LARGE::template Type<K, V> |
using IsHybridMap = std::true_type |
using Iterator = IteratorTemplate<false, EntryIteratorBase> |
using ConstIterator = IteratorTemplate<true, EntryIteratorBase> |
using KeyIterator = IteratorTemplate<false, KeyIteratorBase> |
using ConstKeyIterator = IteratorTemplate<true, KeyIteratorBase> |
using ValueIterator = IteratorTemplate<false, ValueIteratorBase> |
using ConstValueIterator = IteratorTemplate<true, ValueIteratorBase> |
HybridMap | ( | ) |
~HybridMap | ( | ) |
Iterator Begin | ( | ) |
Returns an iterator pointing to the first entry of this map.
Iterator End | ( | ) |
Returns an iterator pointing just behind the last entry of this map.
ConstIterator Begin | ( | ) | const |
Returns an iterator pointing to the first entry of this map.
ConstIterator End | ( | ) | const |
Returns an iterator pointing just behind the last entry of this map.
KeyIterator GetKeys | ( | ) |
Returns a foreach iterator to iterate over all keys of this map.
ConstKeyIterator GetKeys | ( | ) | const |
Returns a foreach iterator to iterate over all keys of this map.
ValueIterator GetValues | ( | ) |
Returns a foreach iterator to iterate over all values of this map.
ConstValueIterator GetValues | ( | ) | const |
Returns a foreach iterator to iterate over all values of this map.
MAXON_OPERATOR_MOVE_ASSIGNMENT | ( | HybridMap< K, V, SMALL, LARGE, THRESHOLD, REVERSE_THRESHOLD > | ) |
Result<void> CopyFromImpl | ( | MAP && | src, |
COLLECTION_RESIZE_FLAGS | resizeFlags, | ||
OverloadRank0 | |||
) |
SFINAEHelper<Result<void>, typename std::remove_reference<MAP>::type::IsHybridMap>::type CopyFromImpl | ( | MAP && | src, |
COLLECTION_RESIZE_FLAGS | resizeFlags, | ||
OverloadRank1 | |||
) |
void Flush | ( | ) |
Flushes the map so that it is empty afterwards. Depending on the underlying implementations, memory may still be held for re-use. If REVERSE_THRESHOLD
is non-negative, Flush() will also switch back to the SMALL
implementation.
void Reset | ( | ) |
Resets the map. This destructs all entries and frees any memory held by the map. The map will also switch to the SMALL
implementation if necessary, so it will be in a state as if it had been newly constructed.
Int GetCount | ( | ) | const |
Returns the number of entries in this map.
Int GetOperationCountForSearch | ( | ) | const |
Returns an estimate of the number of operations needed to locate a given key in this map. This is used when two collections are compared: The iteration goes over the collection which would require more operations for search, and each entry is searched in the other collection.
Int GetMemorySize | ( | ) | const |
Returns the memory usage of this map.
ResultMem SetCapacityHint | ( | Int | capacity, |
COLLECTION_RESIZE_FLAGS | resizeFlags = COLLECTION_RESIZE_FLAGS::ON_GROW_RESERVE_CAPACITY |
||
) |
Increases the internal capacity of the map so that it is prepared to hold at least the given number of elements. This is forwarded to the currently used underlying map implementation.
[in] | capacity | The desired capacity. |
[in] | resizeFlags | If ON_GROW_FIT_TO_SIZE is set, the collection will use only as much memory as needed to hold the data. |
ResultRef<V> InsertKey | ( | const K & | key, |
Bool & | created = BoolLValue() |
||
) |
Finds the value associated with the given key, or creates a corresponding entry if it doesn't exist yet. The value of a new entry has to be initialized afterwards (but its default constructor has already been invoked).
[in] | key | Key of the value to find or create. |
[out] | created | This will be set to true if a new entry has been created successfully, otherwise it will be set to false. |
ResultRef<V> InsertKey | ( | K && | key, |
Bool & | created = BoolLValue() |
||
) |
Finds the value associated with the given key, or creates a corresponding entry if it doesn't exist yet. The value of a new entry has to be initialized afterwards (but its default constructor has already been invoked).
[in] | key | Key of the value to find or create. If a new entry is created, its key will be constructed by move-semantics if possible. |
[out] | created | This will be set to true if a new entry has been created successfully, otherwise it will be set to false. |
ResultMemT<Iterator> InsertEntry | ( | const K & | key, |
Bool & | created = BoolLValue() |
||
) |
Finds the entry with the given key, or creates such an entry if it doesn't exist yet, and returns an iterator pointing to the entry. The value of a new entry has to be initialized afterwards (but its default constructor has already been invoked).
[in] | key | Key of the entry to find or create. |
[out] | created | This will be set to true if a new entry has been created successfully, otherwise it will be set to false. |
ResultMemT<Iterator> InsertEntry | ( | K && | key, |
Bool & | created = BoolLValue() |
||
) |
Finds the entry with the given key, or creates such an entry if it doesn't exist yet, and returns an iterator pointing to the entry. The value of a new entry has to be initialized afterwards (but its default constructor has already been invoked).
[in] | key | Key of the entry to find or create. If a new entry is created, its key will be constructed by move-semantics if possible. |
[out] | created | This will be set to true if a new entry has been created successfully, otherwise it will be set to false. |
ResultMemT<Iterator> Insert | ( | const K & | key, |
const V & | value, | ||
Bool & | created = BoolLValue() |
||
) |
Finds the entry with the given key, or creates such an entry if it doesn't exist yet, and returns an iterator pointing to the entry. The value of the entry will be set to value
in any case.
[in] | key | Key of the entry to find or create. |
[in] | value | This will be copied to the value of the entry. |
[out] | created | This will be set to true if a new entry has been created successfully, otherwise it will be set to false. |
ResultMemT<Iterator> Insert | ( | K && | key, |
const V & | value, | ||
Bool & | created = BoolLValue() |
||
) |
Finds the entry with the given key, or creates such an entry if it doesn't exist yet, and returns an iterator pointing to the entry. The value of the entry will be set to value
in any case.
[in] | key | Key of the entry to find or create. If a new entry is created, its key will be constructed by move-semantics if possible. |
[in] | value | This will be copied to the value of the entry. |
[out] | created | This will be set to true if a new entry has been created successfully, otherwise it will be set to false. |
ResultMemT<Iterator> Insert | ( | const K & | key, |
V && | value, | ||
Bool & | created = BoolLValue() |
||
) |
Finds the entry with the given key, or creates such an entry if it doesn't exist yet, and returns an iterator pointing to the entry. The value of the entry will be set to value
in any case.
[in] | key | Key of the entry to find or create. |
[in] | value | This will be moved to the value of the entry. |
[out] | created | This will be set to true if a new entry has been created successfully, otherwise it will be set to false. |
ResultMemT<Iterator> Insert | ( | K && | key, |
V && | value, | ||
Bool & | created = BoolLValue() |
||
) |
Finds the entry with the given key, or creates such an entry if it doesn't exist yet, and returns an iterator pointing to the entry. The value of the entry will be set to value
in any case.
[in] | key | Key of the entry to find or create. If a new entry is created, its key will be constructed by move-semantics if possible. |
[in] | value | This will be moved to the value of the entry. |
[out] | created | This will be set to true if a new entry has been created successfully, otherwise it will be set to false. |
const V* FindValue | ( | const KEY & | key | ) | const |
Finds the value associated with the given key in this map.
[in] | key | Key to search for. |
V* FindValue | ( | const KEY & | key | ) |
Finds the value associated with the given key in this map.
[in] | key | Key to search for. |
Iterator Find | ( | const KEY & | key | ) |
Finds the entry for the given key in this map.
[in] | key | Key to search for. |
key
, or an invalid iterator if this doesn't exist. ConstIterator Find | ( | const KEY & | key | ) | const |
Finds the entry for the given key in this map.
[in] | key | Key to search for. |
key
, or an invalid iterator if this doesn't exist. Iterator FindFloor | ( | const KEY & | key | ) |
Finds the entry with the greatest key less than or equal to the given key
. If no such entry exists, the returned iterator will be invalid (its operator Bool
will return false). This function is only supported if both underlying implementations support it.
[in] | key | Key to search for. |
key
, or an invalid iterator if this doesn't exist. ConstIterator FindFloor | ( | const KEY & | key | ) | const |
Finds the entry with the greatest key less than or equal to the given key
. If no such entry exists, the returned iterator will be invalid (its operator Bool
will return false). This function is only supported if both underlying implementations support it.
[in] | key | Key to search for. |
key
, or an invalid iterator if this doesn't exist. Removes an entry with the given key from this map (if possible).
[in] | key | Key of the map entry to be be removed. |
IteratorTemplate<false, SUPER> Erase | ( | const IteratorTemplate< false, SUPER > & | position | ) |
Removes the element at position
from this map. The returned iterator will point to the element behind the last removed element.
[in] | position | Iterator pointing to the element to be removed. |
Result<void> UseLargeMap | ( | ) |
Switches to the LARGE
implementation.
Result<void> UseSmallMap | ( | ) |
Switches to the SMALL
implementation.
|
protected |
|
protected |
|
protected |
|
protected |
|
private |
|
protected |