104#ifndef AH_DISPATCHER_H
105#define AH_DISPATCHER_H
136template <
typename Key,
class Operation>
163 template <
typename ...
Pairs>
195 template <
typename ...
Args>
201 std::cerr <<
"Tried to run dispatcher with a key"
202 <<
" which has not been registered" << std::endl;
205 return (ptr->second)(std::forward<Args>(
args)...);
269template <
typename Key,
class Operation>
272 using P = std::pair<Key, Operation>;
278 return p1.first == p2.first;
314 template <
typename ...
Args>
318 return tbl.find(p).second(
args...);
338 bool has(
const Key & key)
const
Tree-based command dispatcher.
bool is_empty() const
Check if the dispatcher is empty.
bool valid_key(const Key &key)
Check if a key is registered.
void insert(const Key &key, Operation op)
Register a key-operation pair.
size_t size() const
Get the number of registered operations.
auto run(const Key &key, Args &&... args) const
Execute the operation associated with a key.
DynList< Key > keys() const
Get all registered keys.
AHDispatcher()=default
Default constructor.
AHDispatcher(const Key &key, Operation op, Pairs ... pairs)
Variadic constructor for initializing with key-operation pairs.
DynMapTree< Key, Operation > tbl
void remove(const Key &key)
Remove a key-operation pair.
Hash-based command dispatcher.
bool has(const Key &key) const
Check if a key is registered.
auto run(const Key &key, Args ... args) const
Execute the operation associated with a key.
ODhashTable< P, Equal > tbl
static size_t fst_hash(const P &p)
void insert(const Key &key, Operation op)
Register a key-operation pair.
static size_t snd_hash(const P &p)
void remove(const Key &key)
Remove a key-operation pair.
AhHashDispatcher()
Default constructor.
std::pair< Key, Operation > P
Dynamic singly linked list with functional programming support.
Generic key-value map implemented on top of a binary search tree.
Data remove(const Key &key)
Deletes the pair key,data
Pair * search(const Key &key) const noexcept
Collect all keys.
bool has(const Key &key) const noexcept
DynList< Key > keys() const
Pair * insert(const Key &key, const Data &data)
Insert a key-value pair.
const size_t & size() const
Returns the cardinality of the set.
bool is_empty() const
returns true if the set is empty
Open addressing hash table with double hashing collision resolution.
size_t snd_hash_fct(const Key &key) noexcept
size_t dft_hash_fct(const Key &key) noexcept
DynList< T > maps(const C &c, Op op)
Classic map operation.
bool operator()(const P &p1, const P &p2) const
Dynamic key-value map based on balanced binary search trees.
Open addressing hash table with double hashing.