poser
A C framework for POsix SERvices
|
A hash table storing any data objects using string keys. More...
#include <poser/core/hashtable.h>
Public Member Functions | |
PSC_HashTable * | PSC_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_HashTableIterator * | PSC_HashTable_iterator (const PSC_HashTable *self) |
Creates an iterator for all entries. | |
void | PSC_HashTable_destroy (PSC_HashTable *self) |
PSC_HashTable destructor. | |
A hash table storing any data objects using string keys.
size_t PSC_HashTable_count | ( | const PSC_HashTable * | self | ) |
PSC_HashTable * PSC_HashTable_create | ( | uint8_t | bits | ) |
PSC_HashTable default constructor.
Creates a new PSC_HashTable
bits | number of bits for the hashes (valid range [2..8]) |
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.
self | the PSC_HashTable |
key | the key |
void PSC_HashTable_destroy | ( | PSC_HashTable * | self | ) |
PSC_HashTable destructor.
All stored objects that have a deleter attached are destroyed as well.
self | the PSC_HashTable |
void * PSC_HashTable_get | ( | const PSC_HashTable * | self, |
const char * | key | ||
) |
Gets an object by key.
self | the PSC_HashTable |
key | the key |
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.
self | the PSC_HashTable |
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.
self | the PSC_HashTable |
key | the key |
obj | the new object |
deleter | optional function to destroy the object |