|
AXOM
Axom provides a robust, flexible software infrastructure for the development of multi-physics applications and computational tools.
|
Provides a generic associative key-value container. More...
#include </home/docs/checkouts/readthedocs.org/user_builds/axom/checkouts/main/src/axom/core/FlatMap.hpp>
Inherits detail::flat_map::SequentialLookupPolicy< Hash::result_type >.
Public Types | |
| using | key_type = KeyType |
| using | mapped_type = ValueType |
| using | size_type = IndexType |
| using | value_type = KeyValuePair |
| using | iterator = IteratorImpl< false > |
| using | const_iterator = IteratorImpl< true > |
| using | View = FlatMapView< KeyType, ValueType, false, Hash > |
| using | ConstView = FlatMapView< KeyType, ValueType, true, Hash > |
Public Member Functions | |
| FlatMap (Allocator allocator=Allocator {}) | |
| Constructs a FlatMap with no elements. More... | |
| FlatMap (IndexType bucket_count, Allocator allocator=Allocator {}) | |
| Constructs a FlatMap with at least a given number of buckets. More... | |
| template<typename InputIt > | |
| FlatMap (InputIt first, InputIt last, IndexType bucket_count=-1) | |
| Constructs a FlatMap with a range of elements. More... | |
| FlatMap (std::initializer_list< value_type > init, IndexType bucket_count=-1) | |
| Constructs a FlatMap with a range of elements. More... | |
| FlatMap (FlatMap &&other) | |
| Move constructor for a FlatMap instance. More... | |
| FlatMap & | operator= (FlatMap &&other) |
| Move assignment operator for a FlatMap instance. More... | |
| FlatMap (const FlatMap &other) | |
| Copy constructor for a FlatMap instance. More... | |
| FlatMap & | operator= (const FlatMap &other) |
| Copy assignment operator for a FlatMap instance. More... | |
| FlatMap (const FlatMap &other, Allocator allocator) | |
| Copy constructor for a FlatMap instance with specified allocator. More... | |
| ~FlatMap () | |
| Destructor for a FlatMap instance. More... | |
| void | swap (FlatMap &other) |
| Swaps the contents of one FlatMap with another. More... | |
| bool | empty () const |
| Returns true if there are no entries in the FlatMap, false otherwise. More... | |
| IndexType | size () const |
| Returns the number of entries stored in the FlatMap. More... | |
| IndexType | count (const KeyType &key) const |
| Return the number of entries matching a given key. More... | |
| bool | contains (const KeyType &key) const |
| Return true if the FlatMap contains a key, false otherwise. More... | |
| void | clear () |
| Erases all elements from the FlatMap. More... | |
| template<typename InputIt > | |
| void | insert (InputIt first, InputIt last) |
| Inserts a range of key-value pairs into the FlatMap. More... | |
| template<typename ExecSpace , typename InputIt > | |
| void | insert (InputIt first, InputIt last) |
| Inserts a range of key-value pairs into the FlatMap. More... | |
| template<typename... Args> | |
| std::pair< iterator, bool > | insert_or_assign (const KeyType &key, Args &&... args) |
| Inserts a key-value pair into the FlatMap. More... | |
| template<typename... Args> | |
| std::pair< iterator, bool > | insert_or_assign (KeyType &&key, Args &&... args) |
| template<typename... Args> | |
| std::pair< iterator, bool > | try_emplace (const KeyType &key, Args &&... args) |
| Inserts a key-value pair into the FlatMap. More... | |
| template<typename... Args> | |
| std::pair< iterator, bool > | try_emplace (KeyType &&key, Args &&... args) |
| iterator | erase (iterator pos) |
| Remove a key-value pair from the FlatMap, specified by iterator. More... | |
| iterator | erase (const_iterator pos) |
| IndexType | erase (const KeyType &key) |
| Remove a key-value pair from the FlatMap, specified by key. More... | |
| IndexType | bucket_count () const |
| Returns the number of buckets allocated in the FlatMap. More... | |
| double | load_factor () const |
| Returns the current load factor of the FlatMap. More... | |
| double | max_load_factor () const |
| Returns the maximum load factor of the FlatMap. More... | |
| Allocator | getAllocator () const |
| Returns the allocator ID the FlatMap is allocated with. More... | |
| void | rehash (IndexType count) |
| Explicitly rehash the FlatMap with a given number of buckets. More... | |
| void | reserve (IndexType count) |
| Reallocate and rehash the FlatMap, such that up to the specified number of elements may be inserted without a rehash. More... | |
| View | view () |
| Returns a read-only view of the FlatMap. More... | |
| ConstView | view () const |
| template<typename ExecSpace > | |
| auto | create (ArrayView< KeyType > keys, ArrayView< ValueType > values, Allocator allocator) -> FlatMap |
| iterator | begin () |
| Returns an iterator to the first valid object in the bucket array. More... | |
| const_iterator | begin () const |
| const_iterator | cbegin () const |
| iterator | end () |
| Returns an iterator to "one past" the last valid object in the bucket array. More... | |
| const_iterator | end () const |
| const_iterator | cend () const |
| iterator | find (const KeyType &key) |
| Try to find an entry with a given key. More... | |
| const_iterator | find (const KeyType &key) const |
| ValueType & | at (const KeyType &key) |
| Try to find an entry with a given key. More... | |
| const ValueType & | at (const KeyType &key) const |
| ValueType & | operator[] (const KeyType &key) |
| Find an entry with a given key. More... | |
| const ValueType & | operator[] (const KeyType &key) const |
| std::pair< iterator, bool > | insert (const value_type &value) |
| Inserts a key-value pair into the FlatMap. More... | |
| std::pair< iterator, bool > | insert (value_type &&value) |
| template<typename InputPair > | |
| std::pair< iterator, bool > | insert (InputPair &&pair) |
| template<typename... InputArgs> | |
| std::pair< iterator, bool > | emplace (InputArgs &&... pair) |
Static Public Member Functions | |
| template<typename ExecSpace > | |
| static FlatMap | create (axom::ArrayView< KeyType > keys, axom::ArrayView< ValueType > values, Allocator allocator=Allocator {}) |
| }@ More... | |
Friends | |
| template<bool Const> | |
| class | IteratorImpl |
| class | FlatMapView< KeyType, ValueType, false, Hash > |
| class | FlatMapView< KeyType, ValueType, true, Hash > |
Provides a generic associative key-value container.
The FlatMap class is a container which maps unique keys to a single value. It supports insertion, removal, and lookup of key-value pairs in amortized constant time.
| KeyType | the type of the keys to hold |
| ValueType | the type of the values to hold |
| Hash | the hash to use with the key type |
| using axom::FlatMap< KeyType, ValueType, Hash >::key_type = KeyType |
| using axom::FlatMap< KeyType, ValueType, Hash >::mapped_type = ValueType |
| using axom::FlatMap< KeyType, ValueType, Hash >::size_type = IndexType |
| using axom::FlatMap< KeyType, ValueType, Hash >::value_type = KeyValuePair |
| using axom::FlatMap< KeyType, ValueType, Hash >::iterator = IteratorImpl<false> |
| using axom::FlatMap< KeyType, ValueType, Hash >::const_iterator = IteratorImpl<true> |
| using axom::FlatMap< KeyType, ValueType, Hash >::View = FlatMapView<KeyType, ValueType, false, Hash> |
| using axom::FlatMap< KeyType, ValueType, Hash >::ConstView = FlatMapView<KeyType, ValueType, true, Hash> |
|
inlineexplicit |
Constructs a FlatMap with no elements.
| [in] | allocator | memory space to store metadata and key-value pairs |
| axom::FlatMap< KeyType, ValueType, Hash >::FlatMap | ( | IndexType | bucket_count, |
| Allocator | allocator = Allocator {} |
||
| ) |
Constructs a FlatMap with at least a given number of buckets.
| [in] | bucket_count | the minimum number of buckets to allocate |
| [in] | allocator | memory space to store metadata and key-value pairs |
References axom::FlatMap< KeyType, ValueType, Hash >::bucket_count(), axom::utilities::ceil(), axom::utilities::countl_zero(), and axom::Allocator::getID().
|
inline |
Constructs a FlatMap with a range of elements.
| [in] | first | iterator pointing to the beginning of the range |
| [in] | last | iterator pointing to the end of the range |
| [in] | bucket_count | minimum number of buckets to allocate (optional) |
|
inlineexplicit |
Constructs a FlatMap with a range of elements.
| [in] | init | a list of pairs to initialize the map with |
| [in] | bucket_count | minimum number of buckets to allocate (optional) |
|
inline |
Move constructor for a FlatMap instance.
| other | the FlatMap to move data from |
References axom::FlatMap< KeyType, ValueType, Hash >::swap().
|
inline |
Copy constructor for a FlatMap instance.
| other | the FlatMap to copy data from |
References axom::Array< T, DIM, SPACE, StoragePolicy >::view().
|
inline |
Copy constructor for a FlatMap instance with specified allocator.
| other | the FlatMap to copy data from | |
| [in] | allocator | memory space to move data to |
References axom::Array< T, DIM, SPACE, StoragePolicy >::view().
|
inline |
Destructor for a FlatMap instance.
References axom::Array< T, DIM, SPACE, StoragePolicy >::view().
|
inline |
Move assignment operator for a FlatMap instance.
| other | the FlatMap to move data from |
References axom::FlatMap< KeyType, ValueType, Hash >::swap().
|
inline |
Copy assignment operator for a FlatMap instance.
| other | the FlatMap to copy data from |
References axom::FlatMap< KeyType, ValueType, Hash >::swap().
|
inline |
Swaps the contents of one FlatMap with another.
References axom::Array< T, DIM, SPACE, StoragePolicy >::swap(), and axom::utilities::swap().
|
inline |
Returns an iterator to the first valid object in the bucket array.
|
inline |
|
inline |
|
inline |
Returns an iterator to "one past" the last valid object in the bucket array.
References axom::FlatMap< KeyType, ValueType, Hash >::bucket_count().
|
inline |
|
inline |
|
inline |
Returns true if there are no entries in the FlatMap, false otherwise.
|
inline |
Returns the number of entries stored in the FlatMap.
| auto axom::FlatMap< KeyType, ValueType, Hash >::find | ( | const KeyType & | key | ) |
Try to find an entry with a given key.
| [in] | key | the key to search for |
References axom::utilities::annotations::end().
| auto axom::FlatMap< KeyType, ValueType, Hash >::find | ( | const KeyType & | key | ) | const |
References axom::utilities::annotations::end().
|
inline |
Try to find an entry with a given key.
| [in] | key | the key to search for |
| std::out_of_range | if the key is not found. |
References axom::FlatMap< KeyType, ValueType, Hash >::end(), and axom::FlatMap< KeyType, ValueType, Hash >::find().
|
inline |
|
inline |
Find an entry with a given key.
If a corresponding value does not exist, a default value for the value type will be inserted for the given key.
| [in] | key | the key to search for |
References axom::FlatMap< KeyType, ValueType, Hash >::try_emplace().
|
inline |
|
inline |
Return the number of entries matching a given key.
This method will always return 0 or 1.
| [in] | key | the key to search for |
References axom::FlatMap< KeyType, ValueType, Hash >::contains().
|
inline |
Return true if the FlatMap contains a key, false otherwise.
| [in] | key | the key to search for |
References axom::FlatMap< KeyType, ValueType, Hash >::end(), and axom::FlatMap< KeyType, ValueType, Hash >::find().
|
inline |
Erases all elements from the FlatMap.
References axom::Array< T, DIM, SPACE, StoragePolicy >::clear(), axom::Array< T, DIM, SPACE, StoragePolicy >::resize(), and axom::Array< T, DIM, SPACE, StoragePolicy >::view().
|
inline |
Inserts a key-value pair into the FlatMap.
If the key already exists in the FlatMap, insertion is skipped. Otherwise, the key-value mapping is inserted into the FlatMap.
| [in] | value | the key-value pair to insert |
|
inline |
|
inline |
|
inline |
| void axom::FlatMap< KeyType, ValueType, Hash >::insert | ( | InputIt | first, |
| InputIt | last | ||
| ) |
Inserts a range of key-value pairs into the FlatMap.
If a key in the range already exists, assigns the value to the existing key in the FlatMap. Otherwise, a new key-value pair is inserted into the FlatMap.
| [in] | first | the beginning of the range of pairs |
| [in] | last | the end of the range of pairs |
| void axom::FlatMap< KeyType, ValueType, Hash >::insert | ( | InputIt | first, |
| InputIt | last | ||
| ) |
Inserts a range of key-value pairs into the FlatMap.
If a key in the range already exists, assigns the value to the existing key in the FlatMap. Otherwise, a new key-value pair is inserted into the FlatMap.
| [in] | first | the beginning of the range of pairs |
| [in] | last | the end of the range of pairs |
| ExecSpace | the execution space in which to perform the batched construction |
References AXOM_LAMBDA, axom::slam::util::distance(), axom::serial::reductions::ReduceSum< ExecSpace, T >::get(), axom::Array< T, DIM, SPACE, StoragePolicy >::resize(), and axom::Array< T, DIM, SPACE, StoragePolicy >::view().
|
inline |
Inserts a key-value pair into the FlatMap.
If the key already exists, assigns the value to the existing key in the FlatMap.
| [in] | key | the key to insert or assign |
| [in] | args | arguments to construct the value with |
|
inline |
|
inline |
Inserts a key-value pair into the FlatMap.
If the key already exists in the FlatMap, insertion is skipped. Otherwise, the key-value mapping is inserted into the FlatMap.
Compared to emplace(), this method only moves-from the value arguments if the key does not exist; otherwise, the input arguments are left as-is.
| [in] | key | the key to insert or assign |
| [in] | args | arguments to construct the value with. |
|
inline |
|
inline |
Remove a key-value pair from the FlatMap, specified by iterator.
| pos | the iterator pointing to the key-value pair to remove |
References axom::FlatMap< KeyType, ValueType, Hash >::erase().
| auto axom::FlatMap< KeyType, ValueType, Hash >::erase | ( | const_iterator | pos | ) |
References axom::utilities::annotations::end().
|
inline |
Remove a key-value pair from the FlatMap, specified by key.
If the key doesn't exist in the FlatMap, does nothing.
| key | the key to remove |
References axom::FlatMap< KeyType, ValueType, Hash >::end(), axom::FlatMap< KeyType, ValueType, Hash >::erase(), and axom::FlatMap< KeyType, ValueType, Hash >::find().
|
inline |
Returns the number of buckets allocated in the FlatMap.
The maximum number of elements that can be stored in the FlatMap without resizing and rehashing is bucket_count() * max_load_factor().
References axom::Array< T, DIM, SPACE, StoragePolicy >::size().
|
inline |
Returns the current load factor of the FlatMap.
References axom::FlatMap< KeyType, ValueType, Hash >::bucket_count().
|
inline |
Returns the maximum load factor of the FlatMap.
|
inline |
Returns the allocator ID the FlatMap is allocated with.
|
inline |
Explicitly rehash the FlatMap with a given number of buckets.
| count | the minimum number of buckets to allocate for the rehash |
References axom::FlatMap< KeyType, ValueType, Hash >::begin(), axom::FlatMap< KeyType, ValueType, Hash >::count(), axom::FlatMap< KeyType, ValueType, Hash >::end(), axom::detail::getAllocatorSpace(), axom::Allocator::getID(), and axom::FlatMap< KeyType, ValueType, Hash >::swap().
|
inline |
Reallocate and rehash the FlatMap, such that up to the specified number of elements may be inserted without a rehash.
| count | the number of elements to fit without a rehash |
References axom::FlatMap< KeyType, ValueType, Hash >::bucket_count(), axom::FlatMap< KeyType, ValueType, Hash >::count(), axom::FlatMap< KeyType, ValueType, Hash >::max_load_factor(), and axom::FlatMap< KeyType, ValueType, Hash >::rehash().
| auto axom::FlatMap< KeyType, ValueType, Hash >::view |
Returns a read-only view of the FlatMap.
| auto axom::FlatMap< KeyType, ValueType, Hash >::view |
|
static |
}@
Constructs and returns a FlatMap given a set of key-value pairs.
Duplicate keys are handled by selecting the last value in the values array corresponding to the equivalent key.
| keys | [in] array of keys for the pairs to insert |
| values | [in] array of values for the pairs to insert |
| allocator | [in] allocator to use for the constructed FlatMap |
| ExecSpace | the execution space in which to perform the batched construction |
| auto axom::FlatMap< KeyType, ValueType, Hash >::create | ( | ArrayView< KeyType > | keys, |
| ArrayView< ValueType > | values, | ||
| Allocator | allocator | ||
| ) | -> FlatMap |
|
friend |
|
friend |
|
friend |