libdom
Loading...
Searching...
No Matches
Classes | Typedefs | Functions
hashtable.h File Reference
#include <stdbool.h>
#include <dom/functypes.h>

Go to the source code of this file.

Classes

struct  dom_hash_vtable
 

Typedefs

typedef struct dom_hash_table dom_hash_table
 
typedef struct dom_hash_vtable dom_hash_vtable
 

Functions

dom_hash_table_dom_hash_create (unsigned int chains, const dom_hash_vtable *vtable, void *pw)
 
dom_hash_table_dom_hash_clone (dom_hash_table *ht)
 
void _dom_hash_destroy (dom_hash_table *ht)
 
bool _dom_hash_add (dom_hash_table *ht, void *key, void *value, bool replace)
 
void * _dom_hash_get (dom_hash_table *ht, void *key)
 
void * _dom_hash_del (dom_hash_table *ht, void *key)
 
void * _dom_hash_iterate (dom_hash_table *ht, uintptr_t *c1, uintptr_t **c2)
 
uint32_t _dom_hash_get_length (dom_hash_table *ht)
 

Typedef Documentation

◆ dom_hash_table

typedef struct dom_hash_table dom_hash_table

◆ dom_hash_vtable

typedef struct dom_hash_vtable dom_hash_vtable

Function Documentation

◆ _dom_hash_add()

bool _dom_hash_add ( dom_hash_table * ht,
void * key,
void * value,
bool replace )

Adds a key/value pair to a hash table

Parameters
htThe hash table context to add the key/value pair to.
keyThe key to associate the value with.
valueThe value to associate the key with.
Returns
true if the add succeeded, false otherwise. (Failure most likely indicates insufficent memory to make copies of the key and value.

◆ _dom_hash_clone()

dom_hash_table * _dom_hash_clone ( dom_hash_table * ht)

Clone a hash table.

Parameters
htHash table to clone.
Returns
The cloned hash table.

◆ _dom_hash_create()

dom_hash_table * _dom_hash_create ( unsigned int chains,
const dom_hash_vtable * vtable,
void * pw )

Create a new hash table, and return a context for it. The memory consumption of a hash table is approximately 8 + (nchains * 12) bytes if it is empty.

Parameters
chainsNumber of chains/buckets this hash table will have. This should be a prime number, and ideally a prime number just over a power of two, for best performance and distribution
vtableClient vtable
pwClient private data
Returns
struct dom_hash_table containing the context of this hash table or NULL if there is insufficent memory to create it and its chains.

◆ _dom_hash_del()

void * _dom_hash_del ( struct dom_hash_table * ht,
void * key )

Delete the key from the hashtable.

Parameters
htThe hashtable object
keyThe key to delete
Returns
The deleted value

◆ _dom_hash_destroy()

void _dom_hash_destroy ( dom_hash_table * ht)

Destroys a hash table, freeing all memory associated with it.

Parameters
htHash table to destroy. After the function returns, this will nolonger be valid

◆ _dom_hash_get()

void * _dom_hash_get ( struct dom_hash_table * ht,
void * key )

Looks up a the value associated with with a key from a specific hash table.

Parameters
htThe hash table context to look up
keyThe key to search for
Returns
The value associated with the key, or NULL if it was not found.

◆ _dom_hash_get_length()

uint32_t _dom_hash_get_length ( struct dom_hash_table * ht)

Get the number of elements in this hash table

Parameters
htThe hash table
Returns
the number of elements

◆ _dom_hash_iterate()

void * _dom_hash_iterate ( struct dom_hash_table * ht,
uintptr_t * c1,
uintptr_t ** c2 )

Iterate through all available hash keys.

Parameters
htThe hash table context to iterate.
c1Pointer to first context
c2Pointer to second context (set to 0 on first call)
Returns
The next hash key, or NULL for no more keys