template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
class immer::map< K, T, Hash, Equal, MemoryPolicy, B >
Immutable unordered mapping of values from type K
to type T
.
- Template Parameters
-
K | The type of the keys. |
T | The type of the values to be stored in the container. |
Hash | The type of a function object capable of hashing values of type T . |
Equal | The type of a function object capable of comparing values of type T . |
MemoryPolicy | Memory management policy. See memory_policy. |
This cotainer provides a good trade-off between cache locality, search, update performance and structural sharing. It does so by storing the data in contiguous chunks of :math:2^{B}
elements. When storing big objects, the size of these contiguous chunks can become too big, damaging performance. If this is measured to be problematic for a specific use-case, it can be solved by using a immer::box
to wrap the type T
.
Example .. literalinclude:: ../example/map/intro.cpp :language: c++ :start-after: intro/start :end-before: intro/end
Definition at line 64 of file map.hpp.
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
Default constructor. It creates a set of size() == 0
. It does not allocate memory and its complexity is .
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
const T& immer::map< K, T, Hash, Equal, MemoryPolicy, B >::at |
( |
const K & |
k | ) |
const |
|
inline |
Returns a const
reference to the values associated to the key k
. If the key is not contained in the map, throws an std::out_of_range
error. It does not allocate memory and its complexity is effectively .
Definition at line 203 of file map.hpp.
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
Returns an iterator pointing at the first element of the collection. It does not allocate memory and its complexity is .
Definition at line 165 of file map.hpp.
Referenced by SerializeImmerMap().
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
Returns an iterator pointing just after the last element of the collection. It does not allocate and its complexity is .
Definition at line 171 of file map.hpp.
Referenced by SerializeImmerMap().
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
const T* immer::map< K, T, Hash, Equal, MemoryPolicy, B >::find |
( |
const K & |
k | ) |
const |
|
inline |
Returns a pointer to the value associated with the key k
. If the key is not contained in the map, a nullptr
is returned. It does not allocate memory and its complexity is effectively .
.. admonition:: Why doesn't this function return an iterator?
Associative containers from the C++ standard library provide a find
method that returns an iterator pointing to the element in the container or end()
when the key is missing. In the case of an unordered container, the only meaningful thing one may do with it is to compare it with the end, to test if the find was succesfull, and dereference it. This comparison is cumbersome compared to testing for a non-empty optional value. Furthermore, for an immutable container, returning an iterator would have some additional performance cost, with no benefits otherwise.
In our opinion, this function should return a std::optional<const T&>
but this construction is not valid in any current standard. As a compromise we return a pointer, which has similar syntactic properties yet it is unfortunatelly unnecessarily unrestricted.
Definition at line 236 of file map.hpp.
Referenced by CDeterministicMNList::AddMN(), CDeterministicMNList::AddUniqueProperty(), CDeterministicMNList::DeleteUniqueProperty(), CDeterministicMNList::GetMN(), CDeterministicMNList::GetMNByInternalId(), CDeterministicMNList::GetUniquePropertyMN(), CDeterministicMNList::IsMNPoSeBanned(), CDeterministicMNList::IsMNValid(), and CDeterministicMNList::UpdateMN().
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
Returns a map containing the association value
. If the key is already in the map, it replaces its association in the map. It may allocate memory and its complexity is effectively .
Definition at line 254 of file map.hpp.
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
bool immer::map< K, T, Hash, Equal, MemoryPolicy, B >::operator== |
( |
const map< K, T, Hash, Equal, MemoryPolicy, B > & |
other | ) |
const |
|
inline |
Returns whether the sets are equal.
Definition at line 243 of file map.hpp.
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
const T& immer::map< K, T, Hash, Equal, MemoryPolicy, B >::operator[] |
( |
const K & |
k | ) |
const |
|
inline |
Returns a const
reference to the values associated to the key k
. If the key is not contained in the map, it returns a default constructed value. It does not allocate memory and its complexity is effectively .
Definition at line 194 of file map.hpp.
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
template<typename K, typename T, typename Hash = std::hash<K>, typename Equal = std::equal_to<K>, typename MemoryPolicy = default_memory_policy, detail::hamts::bits_t B = default_bits>
template<typename Fn >
Returns a map replacing the association (k, v)
by the association new association (k, fn(v))
, where v
is the currently associated value for k
in the map or a default constructed value otherwise. It may allocate memory and its complexity is effectively .
Definition at line 274 of file map.hpp.