Communication Library for Autonomous Systems v1.0
Reliable and secure communication library for autonomous vehicle systems
Loading...
Searching...
No Matches
StaticSizeHashedCache< V, N > Class Template Reference

A hash cache with a static size, using linear probing for collision resolution. More...

#include <static_size_hashed_cache.h>

Public Member Functions

 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.
 
Vget (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.
 

Detailed Description

template<typename V, size_t N = 1000>
class StaticSizeHashedCache< V, N >

A hash cache with a static size, using linear probing for collision resolution.

Template Parameters
VThe type of the values to be stored in the cache.
NThe static size of the cache.

Constructor & Destructor Documentation

◆ StaticSizeHashedCache()

template<typename V , size_t N = 1000>
StaticSizeHashedCache< V, N >::StaticSizeHashedCache ( )
inline

Constructs a new StaticSizeHashedCache object. Initializes the cache as empty.

Member Function Documentation

◆ add()

template<typename V , size_t N = 1000>
void StaticSizeHashedCache< V, N >::add ( long int  key,
V  value 
)
inline

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
keyThe key to add.
valueThe value to associate with the key.
Exceptions
std::runtime_errorif the cache is full and a new key is being added.

◆ contains()

template<typename V , size_t N = 1000>
bool StaticSizeHashedCache< V, N >::contains ( long int  key) const
inline

Determines if a key is already in the data structure. It uses linear probing to find the key.

Parameters
keyThe key to look for.
Returns
true if the key is in the cache, false otherwise.

◆ for_each()

template<typename V , size_t N = 1000>
template<typename F >
void StaticSizeHashedCache< V, N >::for_each ( F &&  fn)
inline

Iterate over all occupied entries and apply a functor. The functor receives (key, value&) as parameters.

Template Parameters
FCallable type

◆ get()

template<typename V , size_t N = 1000>
V * StaticSizeHashedCache< V, N >::get ( long int  key)
inline

Retrieves a pointer to the value associated with a given key. It uses linear probing to find the key.

Parameters
keyThe key to look for.
Returns
A pointer to the value if the key is found, otherwise nullptr.

The documentation for this class was generated from the following files: