32 void add(
long int key,
V value) {
34 size_t index = hash(key);
36 for (
size_t i = 0;
i <
N; ++
i) {
46 throw std::runtime_error(
"Cache is full");
57 size_t index = hash(key);
59 for (
size_t i = 0;
i <
N; ++
i) {
80 size_t index = hash(key);
82 for (
size_t i = 0;
i <
N; ++
i) {
100 template <
typename F>
102 for (
size_t i = 0;
i <
N; ++
i) {
104 fn(_keys[
i], _values[
i]);
115 size_t hash(
long int key)
const {
116 return static_cast<unsigned long long>(key) %
N;
119 std::array<long int, N> _keys;
120 std::array<V, N> _values;
121 std::array<bool, N> _occupied;
A hash cache with a static size, using linear probing for collision resolution.
Definition static_size_hashed_cache.h:15
void for_each(F &&fn)
Iterate over all occupied entries and apply a functor. The functor receives (key, value&) as paramete...
Definition static_size_hashed_cache.h:101
void add(long int key, V value)
Adds a key-value pair to the cache. If the key already exists, its value is updated....
Definition static_size_hashed_cache.h:32
V * get(long int key)
Retrieves a pointer to the value associated with a given key. It uses linear probing to find the key.
Definition static_size_hashed_cache.h:55
StaticSizeHashedCache()
Constructs a new StaticSizeHashedCache object. Initializes the cache as empty.
Definition static_size_hashed_cache.h:21
bool contains(long int key) const
Determines if a key is already in the data structure. It uses linear probing to find the key.
Definition static_size_hashed_cache.h:78
Select_Debug<(Traits< T >::debugged &&Traits< Debug >::error)> db(Debug_Error l)
Definition debug.h:166
@ TRC
Definition debug.h:231