34#include <NDEVR/BaseValues.h>
35#include <NDEVR/LibAssert.h>
36#include <NDEVR/Buffer.h>
37#define NDEVR_USE_ROBIN_MAP 1
38#if NDEVR_USE_ROBIN_MAP
39 #include "tsl/robin_map.h"
40 #define MAP_BASE tsl::robin_map
42 #include <unordered_map>
43 #define MAP_BASE MAP_BASE
62 template<
class t_key,
class t_value,
class t_hash = std::hash<t_key>>
70 : MAP_BASE<t_key, t_value, t_hash>()
77 template<
class t_key_type>
78 [[nodiscard]]
bool hasKey(
const t_key_type& key)
const
80 return MAP_BASE<t_key, t_value, t_hash>::find(key) != MAP_BASE<t_key, t_value, t_hash>::end();
87 void add(
const t_key& key,
const t_value& value)
89 MAP_BASE<t_key, t_value, t_hash>::try_emplace(key, value);
96 template<
class t_key_type>
97 void add(
const t_key_type& key,
const t_value& value)
99 MAP_BASE<t_key, t_value, t_hash>::try_emplace(t_key(key), value);
106 void add(
const t_key& key)
108 MAP_BASE<t_key, t_value, t_hash>::try_emplace(key);
116 MAP_BASE<t_key, t_value>::try_emplace(std::move(key));
123 template<
class t_key_type>
124 [[nodiscard]]
const t_value&
get(
const t_key_type& key)
const
126 return MAP_BASE<t_key, t_value, t_hash>::at(key);
133 template<
class t_key_type>
134 [[nodiscard]] t_value&
get(
const t_key_type& key)
136 lib_assert(
hasKey(key),
"Tried to get from Dictionary, without having key");
137 return MAP_BASE<t_key, t_value, t_hash>::at(key);
143 template<class t_index_type = uint04, class t_memory_manager = BufferAllocator<t_key, DetermineAlignment<sizeof(t_key)>(),
ObjectInfo<t_key>::Primitive, t_index_type,
false>>
147 for (
const auto& kv : (*
this))
157 template<class t_index_type = uint04, class t_memory_manager = BufferAllocator<t_value, DetermineAlignment<sizeof(t_value)>(),
ObjectInfo<t_value>::Primitive, t_index_type,
false>>
161 for (
const auto& kv : (*
this))
175 for (
const auto& location : *
this)
177 if (location.first == key)
181 return Constant<uint04>::Invalid;
189 erase(std::next(MAP_BASE<t_key, t_value, t_hash>::begin(), index)->
first);
198 return std::next(MAP_BASE<t_key, t_value, t_hash>::begin(), index);
204 [[nodiscard]]
decltype(
auto)
first()
const
206 return MAP_BASE<t_key, t_value, t_hash>::begin();
213 template<
class t_key_type>
214 void set(
const t_key_type& key,
const t_value& value)
216 MAP_BASE<t_key, t_value, t_hash>::at(key) = value;
223 template<
class t_key_type>
224 [[nodiscard]]
const t_value&
operator[](
const t_key_type& key)
const
226 lib_assert(
hasKey(key),
"Tried to get from Dictionary, without having key");
227 return MAP_BASE<t_key, t_value, t_hash>::at(key);
234 template<
class t_key_type>
237 return MAP_BASE<t_key, t_value, t_hash>::operator[](key);
245 return cast<uint04>(MAP_BASE<t_key, t_value, t_hash>::size());
The equivelent of std::vector but with a bit more control.
A dummy base class for all Dictionary templates Used to more easily track inheritance for the templat...
bool hasKey(const t_key_type &key) const
Checks whether the dictionary contains the given key.
Dictionary()
Constructs an empty Dictionary.
decltype(auto) first() const
decltype(auto) getFromIndex(uint04 index) const
Retrieves an iterator to the entry at the given iteration index.
t_value & operator[](const t_key_type &key)
Subscript operator that retrieves or inserts the value associated with the given key.
void add(const t_key_type &key, const t_value &value)
Inserts a key-value pair using a convertible key type, if the key does not already exist.
void add(t_key &&key)
Inserts a key with a default-constructed value using move semantics, if the key does not already exis...
void removeIndex(uint04 index)
Removes the entry at the given iteration index.
void add(const t_key &key)
Inserts a key with a default-constructed value if the key does not already exist.
uint04 indexOf(const t_key &key) const
Finds the iteration index of the given key within the dictionary.
void set(const t_key_type &key, const t_value &value)
Sets the value for an existing key, replacing the previous value.
Buffer< t_key, t_memory_manager > keys() const
Collects all keys in the dictionary into a Buffer.
t_value & get(const t_key_type &key)
Retrieves a mutable reference to the value associated with the given key.
void add(const t_key &key, const t_value &value)
Inserts a key-value pair if the key does not already exist.
Buffer< t_value, t_memory_manager > values() const
Collects all values in the dictionary into a Buffer.
const t_value & operator[](const t_key_type &key) const
Const subscript operator that retrieves the value associated with the given key.
const t_value & get(const t_key_type &key) const
Retrieves a const reference to the value associated with the given key.
uint04 size() const
Returns the number of entries in the dictionary.
The primary namespace for the NDEVR SDK.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Information about the object.