Class mata::utils::TwoDimensionalMap¶
-
template<typename T, bool track_inverted = true, size_t MAX_MATRIX_SIZE = 50'000'000>
class TwoDimensionalMap¶ A two-dimensional map that can be used to store pairs of values and their associated value.
This class can handle both small and large maps efficiently.
The largest matrix of pairs of we are brave enough to allocate is 50’000’000 for 8 Byte values. So ten million cells is close to 100 MB. If the number is larger, then we do not allocate a matrix, but use a vector of unordered maps (vec_map_storage). The unordered_map seems to be about twice slower.
- Template Parameters:
T – Type of the values stored in the map. Must be an unsigned type.
track_inverted – Whether to track inverted indices for the first and second dimensions. To use this feature correctly, the mapping has to be reversible.
MAX_MATRIX_SIZE – Maximum size of the matrix before switching to vector of unordered maps.
Public Functions
-
inline TwoDimensionalMap(const size_t first_dim_size, const size_t second_dim_size)¶
Constructor for TwoDimensionalMap.
- Parameters:
first_dim_size – Size of the first dimension.
second_dim_size – Size of the second dimension.
-
inline T get(const T first, const T second) const¶
Get the value associated with a pair of keys.
- Parameters:
first – First key.
second – Second key.
- Returns:
The value associated with the pair, or std::numeric_limits<T>::max() if not found.
-
inline void insert(const T first, const T second, const T value)¶
Insert a value associated with a pair of keys.
- Parameters:
first – First key.
second – Second key.
value – Value to associate with the pair.