poser
A C framework for POsix SERvices
Loading...
Searching...
No Matches
PSC_HashTable Class Reference

A hash table storing any data objects using string keys. More...

#include <poser/core/hashtable.h>

Public Member Functions

PSC_HashTablePSC_HashTable_create (uint8_t bits)
 PSC_HashTable default constructor.
 
void PSC_HashTable_set (PSC_HashTable *self, const char *key, void *obj, void(*deleter)(void *))
 Set a new object for a key.
 
int PSC_HashTable_delete (PSC_HashTable *self, const char *key)
 Deletes the object with the specified key.
 
size_t PSC_HashTable_count (const PSC_HashTable *self)
 Number of entries.
 
void * PSC_HashTable_get (const PSC_HashTable *self, const char *key)
 Gets an object by key.
 
PSC_HashTableIteratorPSC_HashTable_iterator (const PSC_HashTable *self)
 Creates an iterator for all entries.
 
void PSC_HashTable_destroy (PSC_HashTable *self)
 PSC_HashTable destructor.
 

Detailed Description

A hash table storing any data objects using string keys.

Member Function Documentation

◆ PSC_HashTable_count()

size_t PSC_HashTable_count ( const PSC_HashTable self)

Number of entries.

Parameters
selfthe PSC_HashTable
Returns
the number of entries

◆ PSC_HashTable_create()

PSC_HashTable * PSC_HashTable_create ( uint8_t  bits)

PSC_HashTable default constructor.

Creates a new PSC_HashTable

Parameters
bitsnumber of bits for the hashes (valid range [2..8])
Returns
a newly created PSC_HashTable

◆ PSC_HashTable_delete()

int PSC_HashTable_delete ( PSC_HashTable self,
const char *  key 
)

Deletes the object with the specified key.

If the object has a deleter attached, it is also destroyed.

Parameters
selfthe PSC_HashTable
keythe key
Returns
1 if an object was deleted, 0 otherwise

◆ PSC_HashTable_destroy()

void PSC_HashTable_destroy ( PSC_HashTable self)

PSC_HashTable destructor.

All stored objects that have a deleter attached are destroyed as well.

Parameters
selfthe PSC_HashTable

◆ PSC_HashTable_get()

void * PSC_HashTable_get ( const PSC_HashTable self,
const char *  key 
)

Gets an object by key.

Parameters
selfthe PSC_HashTable
keythe key
Returns
the object stored for the give key, or NULL

◆ PSC_HashTable_iterator()

PSC_HashTableIterator * PSC_HashTable_iterator ( const PSC_HashTable self)

Creates an iterator for all entries.

The iterator contains a snapshot of all objects currently stored, modifications to the PSC_HashTable will not be reflected in the iterator. In its initial state, the iterator points to an invalid position.

Parameters
selfthe PSC_HashTable
Returns
an iterator

◆ PSC_HashTable_set()

void PSC_HashTable_set ( PSC_HashTable self,
const char *  key,
void *  obj,
void(*)(void *)  deleter 
)

Set a new object for a key.

If there was already an object for the given key, it is replaced. The old object is destroyed if it has a deleter attached.

Parameters
selfthe PSC_HashTable
keythe key
objthe new object
deleteroptional function to destroy the object

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