|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Hash-based command dispatcher. More...
#include <ah-dispatcher.H>
Classes | |
| struct | Equal |
Public Member Functions | |
| AhHashDispatcher () | |
| Default constructor. | |
| void | insert (const Key &key, Operation op) |
| Register a key-operation pair. | |
| template<typename ... Args> | |
| auto | run (const Key &key, Args ... args) const |
| Execute the operation associated with a key. | |
| void | remove (const Key &key) |
| Remove a key-operation pair. | |
| bool | has (const Key &key) const |
| Check if a key is registered. | |
Private Types | |
| using | P = std::pair< Key, Operation > |
Static Private Member Functions | |
| static size_t | fst_hash (const P &p) |
| static size_t | snd_hash (const P &p) |
Private Attributes | |
| ODhashTable< P, Equal > | tbl |
Hash-based command dispatcher.
Maps keys to operations using a hash table (ODhashTable). Provides O(1) average lookup, insertion, and removal.
| Key | The key type (must be hashable) |
| Operation | The callable type |
Use this when:
Use AHDispatcher instead when:
Key comparison is simpler than hashing
Definition at line 270 of file ah-dispatcher.H.
|
private |
Definition at line 272 of file ah-dispatcher.H.
|
inline |
Default constructor.
Definition at line 290 of file ah-dispatcher.H.
Definition at line 282 of file ah-dispatcher.H.
References Aleph::dft_hash_fct().
|
inline |
Check if a key is registered.
| key | The key to check. |
Definition at line 338 of file ah-dispatcher.H.
References AhHashDispatcher< Key, Operation >::tbl.
|
inline |
Register a key-operation pair.
| key | The key to register. |
| op | The operation to associate with the key. |
Definition at line 299 of file ah-dispatcher.H.
References Aleph::maps(), and AhHashDispatcher< Key, Operation >::tbl.
|
inline |
Remove a key-operation pair.
| key | The key to remove. |
Definition at line 326 of file ah-dispatcher.H.
References AhHashDispatcher< Key, Operation >::tbl.
|
inline |
Execute the operation associated with a key.
| Args | Types of arguments to pass to the operation. |
| key | The key identifying the operation. |
| args | Arguments to forward to the operation. |
| std::domain_error | if the key is not found. |
Definition at line 315 of file ah-dispatcher.H.
References Aleph::maps(), and AhHashDispatcher< Key, Operation >::tbl.
Definition at line 283 of file ah-dispatcher.H.
References Aleph::snd_hash_fct().
|
private |
Definition at line 285 of file ah-dispatcher.H.
Referenced by AhHashDispatcher< Key, Operation >::has(), AhHashDispatcher< Key, Operation >::insert(), AhHashDispatcher< Key, Operation >::remove(), and AhHashDispatcher< Key, Operation >::run().