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
46 template<
class t_key,
class t_value,
class t_hash = std::hash<t_key>>
47 class Dictionary :
public MAP_BASE<t_key, t_value, t_hash>
51 : MAP_BASE<t_key, t_value, t_hash>()
53 [[nodiscard]]
bool hasKey(
const t_key& key)
const
55 return MAP_BASE<t_key, t_value, t_hash>::find(key) != MAP_BASE<t_key, t_value, t_hash>::end();
57 void add(
const t_key& key,
const t_value& value)
59 MAP_BASE<t_key, t_value, t_hash>::try_emplace(key, value);
62 void add(
const t_key& key)
64 MAP_BASE<t_key, t_value, t_hash>::try_emplace(key);
68 MAP_BASE<t_key, t_value>::try_emplace(std::move(key));
70 [[nodiscard]]
const t_value&
get(
const t_key& key)
const
72 return MAP_BASE<t_key, t_value, t_hash>::at(key);
74 [[nodiscard]] t_value&
get(
const t_key& key)
77 return MAP_BASE<t_key, t_value, t_hash>::at(key);
83 for (
const auto& kv : (*
this))
93 for (
const auto& kv : (*
this))
102 for (
const auto& location : *
this)
104 if (location.first == key)
112 erase(std::next(MAP_BASE<t_key, t_value, t_hash>::begin(), index)->first);
116 return std::next(MAP_BASE<t_key, t_value, t_hash>::begin(), index)->second;
126 void set(
const t_key& key,
const t_value& value)
128 MAP_BASE<t_key, t_value, t_hash>::at(key) = value;
131 [[nodiscard]]
const t_value&
operator[](
const t_key& key)
const
133 lib_assert(
hasKey(key),
"Tried to get from Dictionary, without having key");
134 return MAP_BASE<t_key, t_value, t_hash>::at(key);
138 return MAP_BASE<t_key, t_value, t_hash>::operator[](key);
142 return cast<uint04>(MAP_BASE<t_key, t_value, t_hash>::size());
#define lib_assert(expression, message)
Asserts some logic in the code. Disabled in non debug mode by default. Can be re-enabled in release u...
Definition LibAssert.h:70
Definition Pointer.hpp:297
The equivelent of std::vector but with a bit more control. The basic array unit of the library.
Definition Buffer.hpp:64
Definition Dictionary.h:48
void add(const t_key &key)
Definition Dictionary.h:62
const t_value & getFromIndex(uint04 index) const
Definition Dictionary.h:114
const t_value & get(const t_key &key) const
Definition Dictionary.h:70
uint04 indexOf(const t_key &key) const
Definition Dictionary.h:99
Buffer< t_key, t_index_type, t_memory_allocator, t_memory_manager > keys() const
Definition Dictionary.h:80
void add(const t_key &key, const t_value &value)
Definition Dictionary.h:57
bool hasKey(const t_key &key) const
Definition Dictionary.h:53
Dictionary()
Definition Dictionary.h:50
void removeIndex(uint04 index)
Definition Dictionary.h:110
t_value & operator[](const t_key &key)
Definition Dictionary.h:136
uint04 size() const
Definition Dictionary.h:140
const t_value & operator[](const t_key &key) const
Definition Dictionary.h:131
void set(const t_key &key, const t_value &value)
Definition Dictionary.h:126
Buffer< t_value, t_index_type, t_memory_allocator, t_memory_manager > values() const
Definition Dictionary.h:90
t_value & get(const t_key &key)
Definition Dictionary.h:74
void add(t_key &&key)
Definition Dictionary.h:66
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
Definition BaseValues.hpp:120
constexpr t_to cast(const Angle< t_from > &value)
Definition Angle.h:514
Definition BaseValues.hpp:272