A hash cache with a static size, using linear probing for collision resolution.
More...
#include <static_size_hashed_cache.h>
|
| StaticSizeHashedCache () |
| Constructs a new StaticSizeHashedCache object. Initializes the cache as empty.
|
|
void | add (long int key, V value) |
| Adds a key-value pair to the cache. If the key already exists, its value is updated. It uses linear probing to find a vacant spot if a collision occurs.
|
|
V * | get (long int key) |
| Retrieves a pointer to the value associated with a given key. It uses linear probing to find the key.
|
|
bool | contains (long int key) const |
| Determines if a key is already in the data structure. It uses linear probing to find the key.
|
|
template<typename F > |
void | for_each (F &&fn) |
| Iterate over all occupied entries and apply a functor. The functor receives (key, value&) as parameters.
|
|
A hash cache with a static size, using linear probing for collision resolution.
- Template Parameters
-
V | The type of the values to be stored in the cache. |
N | The static size of the cache. |
◆ StaticSizeHashedCache()
◆ add()
Adds a key-value pair to the cache. If the key already exists, its value is updated. It uses linear probing to find a vacant spot if a collision occurs.
- Parameters
-
key | The key to add. |
value | The value to associate with the key. |
- Exceptions
-
std::runtime_error | if the cache is full and a new key is being added. |
◆ contains()
Determines if a key is already in the data structure. It uses linear probing to find the key.
- Parameters
-
- Returns
- true if the key is in the cache, false otherwise.
◆ for_each()
Iterate over all occupied entries and apply a functor. The functor receives (key, value&) as parameters.
- Template Parameters
-
◆ get()
Retrieves a pointer to the value associated with a given key. It uses linear probing to find the key.
- Parameters
-
- Returns
- A pointer to the value if the key is found, otherwise nullptr.
The documentation for this class was generated from the following files: