33#include <NDEVR/BaseValues.h>
34#include <NDEVR/LibAssert.h>
35#include <NDEVR/Buffer.h>
36#define NDEVR_USE_ROBIN_MAP 1
37#if NDEVR_USE_ROBIN_MAP
38 #include "tsl/robin_map.h"
39 #define MAP_BASE tsl::robin_map
41 #include <unordered_map>
42 #define MAP_BASE MAP_BASE
59 template<
class t_key,
class t_value,
class t_hash = std::hash<t_key>>
66 [[nodiscard]]
bool hasKey(
const t_key& key)
const
68 return MAP_BASE<t_key, t_value, t_hash>::find(key) != MAP_BASE<t_key, t_value, t_hash>::end();
70 void add(
const t_key& key,
const t_value& value)
72 MAP_BASE<t_key, t_value, t_hash>::try_emplace(key, value);
75 void add(
const t_key& key)
77 MAP_BASE<t_key, t_value, t_hash>::try_emplace(key);
81 MAP_BASE<t_key, t_value>::try_emplace(std::move(key));
83 [[nodiscard]]
const t_value&
get(
const t_key& key)
const
85 return MAP_BASE<t_key, t_value, t_hash>::at(key);
87 [[nodiscard]] t_value&
get(
const t_key& key)
90 return MAP_BASE<t_key, t_value, t_hash>::at(key);
96 for (
const auto& kv : (*
this))
106 for (
const auto& kv : (*
this))
115 for (
const auto& location : *
this)
117 if (location.first == key)
125 erase(std::next(MAP_BASE<t_key, t_value, t_hash>::begin(), index)->first);
129 return std::next(MAP_BASE<t_key, t_value, t_hash>::begin(), index)->second;
131 void set(
const t_key& key,
const t_value& value)
133 MAP_BASE<t_key, t_value, t_hash>::at(key) = value;
135 [[nodiscard]]
const t_value&
operator[](
const t_key& key)
const
137 lib_assert(
hasKey(key),
"Tried to get from Dictionary, without having key");
138 return MAP_BASE<t_key, t_value, t_hash>::at(key);
142 return MAP_BASE<t_key, t_value, t_hash>::operator[](key);
146 return cast<uint04>(MAP_BASE<t_key, t_value, t_hash>::size());
#define MAP_BASE
Definition Dictionary.h:39
#define lib_assert(expression, message)
Definition LibAssert.h:61
Specific logic for reserving memory for a Buffer. When managed, and more memory is needed memory is r...
Definition Pointer.hpp:311
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:56
A dummy base class for all Dictionary templates Used to more easily track inheritance for the templat...
Definition Dictionary.h:51
A hash-based key-value store, useful for quick associative lookups. Key features include:
Definition Dictionary.h:61
void add(const t_key &key)
Definition Dictionary.h:75
const t_value & getFromIndex(uint04 index) const
Definition Dictionary.h:127
const t_value & get(const t_key &key) const
Definition Dictionary.h:83
uint04 indexOf(const t_key &key) const
Definition Dictionary.h:112
Buffer< t_key, t_index_type, t_memory_allocator, t_memory_manager > keys() const
Definition Dictionary.h:93
void add(const t_key &key, const t_value &value)
Definition Dictionary.h:70
bool hasKey(const t_key &key) const
Definition Dictionary.h:66
Dictionary()
Definition Dictionary.h:63
void removeIndex(uint04 index)
Definition Dictionary.h:123
t_value & operator[](const t_key &key)
Definition Dictionary.h:140
uint04 size() const
Definition Dictionary.h:144
const t_value & operator[](const t_key &key) const
Definition Dictionary.h:135
void set(const t_key &key, const t_value &value)
Definition Dictionary.h:131
Buffer< t_value, t_index_type, t_memory_allocator, t_memory_manager > values() const
Definition Dictionary.h:103
t_value & get(const t_key &key)
Definition Dictionary.h:87
void add(t_key &&key)
Definition Dictionary.h:79
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:96
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:375
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Definition BaseValues.hpp:233