Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
AhHashDispatcher< Key, Operation > Class Template Reference

Hash-based command dispatcher. More...

#include <ah-dispatcher.H>

Collaboration diagram for AhHashDispatcher< Key, Operation >:
[legend]

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, Equaltbl
 

Detailed Description

template<typename Key, class Operation>
class AhHashDispatcher< Key, Operation >

Hash-based command dispatcher.

Maps keys to operations using a hash table (ODhashTable). Provides O(1) average lookup, insertion, and removal.

Template Parameters
KeyThe key type (must be hashable)
OperationThe callable type

Use this when:

  • You have many operations and need fast lookup
  • Keys are easily hashable (strings, integers)

Use AHDispatcher instead when:

  • You need ordered iteration over keys
  • Key comparison is simpler than hashing

    Author
    Leandro Rabindranath León

Definition at line 270 of file ah-dispatcher.H.

Member Typedef Documentation

◆ P

template<typename Key , class Operation >
using AhHashDispatcher< Key, Operation >::P = std::pair<Key, Operation>
private

Definition at line 272 of file ah-dispatcher.H.

Constructor & Destructor Documentation

◆ AhHashDispatcher()

Default constructor.

Definition at line 290 of file ah-dispatcher.H.

Member Function Documentation

◆ fst_hash()

template<typename Key , class Operation >
static size_t AhHashDispatcher< Key, Operation >::fst_hash ( const P p)
inlinestaticprivate

Definition at line 282 of file ah-dispatcher.H.

References Aleph::dft_hash_fct().

◆ has()

template<typename Key , class Operation >
bool AhHashDispatcher< Key, Operation >::has ( const Key &  key) const
inline

Check if a key is registered.

Parameters
keyThe key to check.
Returns
true if the key exists.

Definition at line 338 of file ah-dispatcher.H.

References AhHashDispatcher< Key, Operation >::tbl.

◆ insert()

template<typename Key , class Operation >
void AhHashDispatcher< Key, Operation >::insert ( const Key &  key,
Operation  op 
)
inline

Register a key-operation pair.

Parameters
keyThe key to register.
opThe operation to associate with the key.

Definition at line 299 of file ah-dispatcher.H.

References Aleph::maps(), and AhHashDispatcher< Key, Operation >::tbl.

◆ remove()

template<typename Key , class Operation >
void AhHashDispatcher< Key, Operation >::remove ( const Key &  key)
inline

Remove a key-operation pair.

Parameters
keyThe key to remove.

Definition at line 326 of file ah-dispatcher.H.

References AhHashDispatcher< Key, Operation >::tbl.

◆ run()

template<typename Key , class Operation >
template<typename ... Args>
auto AhHashDispatcher< Key, Operation >::run ( const Key &  key,
Args ...  args 
) const
inline

Execute the operation associated with a key.

Template Parameters
ArgsTypes of arguments to pass to the operation.
Parameters
keyThe key identifying the operation.
argsArguments to forward to the operation.
Returns
The return value of the operation.
Exceptions
std::domain_errorif the key is not found.

Definition at line 315 of file ah-dispatcher.H.

References Aleph::maps(), and AhHashDispatcher< Key, Operation >::tbl.

◆ snd_hash()

template<typename Key , class Operation >
static size_t AhHashDispatcher< Key, Operation >::snd_hash ( const P p)
inlinestaticprivate

Definition at line 283 of file ah-dispatcher.H.

References Aleph::snd_hash_fct().

Member Data Documentation

◆ tbl


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