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/latest/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 > |
Public Member Functions | |
FlatMap () | |
Constructs a FlatMap with no elements. More... | |
FlatMap (IndexType bucket_count) | |
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 () | |
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... 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... | |
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... | |
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) |
Friends | |
template<bool Const> | |
class | IteratorImpl |
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> |
|
inline |
Constructs a FlatMap with no elements.
|
explicit |
Constructs a FlatMap with at least a given number of buckets.
[in] | bucket_count | the minimum number of buckets to allocate |
References axom::FlatMap< KeyType, ValueType, Hash >::bucket_count(), axom::utilities::ceil(), axom::utilities::countl_zero(), axom::utilities::max(), and axom::Array< T, DIM, SPACE >::resize().
|
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::FlatMap< KeyType, ValueType, Hash >::bucket_count(), axom::Array< T, DIM, SPACE >::data(), and axom::Array< T, DIM, SPACE >::view().
|
inline |
Destructor for a FlatMap instance.
References axom::FlatMap< KeyType, ValueType, Hash >::bucket_count(), and axom::Array< T, DIM, SPACE >::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 >::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::FlatMap< KeyType, ValueType, Hash >::bucket_count(), and axom::Array< T, DIM, SPACE >::size().
|
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 | ||
) |
|
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 >::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 |
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(), 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::utilities::ceil(), axom::FlatMap< KeyType, ValueType, Hash >::count(), and axom::FlatMap< KeyType, ValueType, Hash >::rehash().
|
friend |