libircbot
library providing a framework for implementing an IRC bot
Loading...
Searching...
No Matches
IBHashTable Class Reference

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

#include <ircbot/hashtable.h>

Public Member Functions

IBHashTableIBHashTable_create (uint8_t bits)
 IBHashTable default constructor. More...
 
void IBHashTable_set (IBHashTable *self, const char *key, void *obj, void(*deleter)(void *))
 Set a new object for a key. More...
 
int IBHashTable_delete (IBHashTable *self, const char *key)
 Deletes the object with the specified key. More...
 
size_t IBHashTable_count (const IBHashTable *self)
 Number of entries. More...
 
void * IBHashTable_get (const IBHashTable *self, const char *key)
 Gets an object by key. More...
 
IBHashTableIteratorIBHashTable_iterator (const IBHashTable *self)
 Creates an iterator for all entries. More...
 
void IBHashTable_destroy (IBHashTable *self)
 IBHashTable destructor. More...
 

Detailed Description

A hash table storing any data objects using string keys.

Member Function Documentation

◆ IBHashTable_count()

size_t IBHashTable_count ( const IBHashTable self)

Number of entries.

Parameters
selfthe IBHashTable
Returns
the number of entries

◆ IBHashTable_create()

IBHashTable * IBHashTable_create ( uint8_t  bits)

IBHashTable default constructor.

Creates a new IBHashTable

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

◆ IBHashTable_delete()

int IBHashTable_delete ( IBHashTable self,
const char *  key 
)

Deletes the object with the specified key.

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

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

◆ IBHashTable_destroy()

void IBHashTable_destroy ( IBHashTable self)

IBHashTable destructor.

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

Parameters
selfthe IBHashTable

◆ IBHashTable_get()

void * IBHashTable_get ( const IBHashTable self,
const char *  key 
)

Gets an object by key.

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

◆ IBHashTable_iterator()

IBHashTableIterator * IBHashTable_iterator ( const IBHashTable self)

Creates an iterator for all entries.

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

Parameters
selfthe IBHashTable
Returns
an iterator

◆ IBHashTable_set()

void IBHashTable_set ( IBHashTable 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 IBHashTable
keythe key
objthe new object
deleteroptional function to destroy the object

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