|
qLibc
|
Hash-table container implementation. More...
Go to the source code of this file.
Macros | |
| #define | DEFAULT_INDEX_RANGE (1000) |
Functions | |
| qhashtbl_t * | qhashtbl (size_t range, int options) |
| Initialize hash table. | |
| bool | qhashtbl_put (qhashtbl_t *tbl, const char *name, const void *data, size_t size) |
| qhashtbl->put(): Put an object into this table. | |
| bool | qhashtbl_putstr (qhashtbl_t *tbl, const char *name, const char *str) |
| qhashtbl->putstr(): Put a string into this table. | |
| bool | qhashtbl_putstrf (qhashtbl_t *tbl, const char *name, const char *format,...) |
| qhashtbl->putstrf(): Put a formatted string into this table. | |
| bool | qhashtbl_putint (qhashtbl_t *tbl, const char *name, const int64_t num) |
| qhashtbl->putint(): Put an integer into this table as a string. | |
| void * | qhashtbl_get (qhashtbl_t *tbl, const char *name, size_t *size, bool newmem) |
| qhashtbl->get(): Get an object from this table. | |
| char * | qhashtbl_getstr (qhashtbl_t *tbl, const char *name, const bool newmem) |
| qhashtbl->getstr(): Finds an object and returns it as a string. | |
| int64_t | qhashtbl_getint (qhashtbl_t *tbl, const char *name) |
| qhashtbl->getint(): Finds an object with given name and returns as integer type. | |
| bool | qhashtbl_remove (qhashtbl_t *tbl, const char *name) |
| qhashtbl->remove(): Remove an object from this table. | |
| bool | qhashtbl_getnext (qhashtbl_t *tbl, qhashtbl_obj_t *obj, const bool newmem) |
| qhashtbl->getnext(): Get next element. | |
| size_t | qhashtbl_size (qhashtbl_t *tbl) |
| qhashtbl->size(): Returns the number of keys in this hashtable. | |
| void | qhashtbl_clear (qhashtbl_t *tbl) |
| qhashtbl->clear(): Clears this hashtable so that it contains no keys. | |
| bool | qhashtbl_debug (qhashtbl_t *tbl, FILE *out) |
| qhashtbl->debug(): Print the hash table for debugging purposes. | |
| void | qhashtbl_lock (qhashtbl_t *tbl) |
| qhashtbl->lock(): Enter critical section. | |
| void | qhashtbl_unlock (qhashtbl_t *tbl) |
| qhashtbl->unlock(): Leave critical section. | |
| void | qhashtbl_free (qhashtbl_t *tbl) |
| qhashtbl->free(): Free hash table | |
Hash-table container implementation.
qhashtbl implements a hash table, which maps keys to values. Keys are unique strings and values are any non-null objects. The creator qhashtbl() has a parameter that affects its performance: the initial hash range. The hash range is the number of slots (pointers) in the hash table. In the case of a hash collision, a single slot stores multiple elements using a linked-list structure, which must be searched sequentially. So lower range than the number of elements decreases the space overhead but increases the number of hash collisions and consequently it increases the time cost to look up an element.
Definition in file qhashtbl.c.
| #define DEFAULT_INDEX_RANGE (1000) |
default value of hash-index range
Definition at line 101 of file qhashtbl.c.
| qhashtbl_t * qhashtbl | ( | size_t | range, |
| int | options ) |
Initialize hash table.
| range | initial size of index range. Value of 0 will use default value, DEFAULT_INDEX_RANGE; |
| options | combination of initialization options. |
| errno | will be set in error condition.
|
Definition at line 127 of file qhashtbl.c.
| bool qhashtbl_put | ( | qhashtbl_t * | tbl, |
| const char * | name, | ||
| const void * | data, | ||
| size_t | size ) |
qhashtbl->put(): Put an object into this table.
| tbl | qhashtbl_t container pointer. |
| name | key name |
| data | data object |
| size | size of data object |
| errno | will be set in error condition.
|
Definition at line 198 of file qhashtbl.c.
| bool qhashtbl_putstr | ( | qhashtbl_t * | tbl, |
| const char * | name, | ||
| const char * | str ) |
qhashtbl->putstr(): Put a string into this table.
| tbl | qhashtbl_t container pointer. |
| name | key name. |
| str | string data. |
| errno | will be set in error condition.
|
Definition at line 279 of file qhashtbl.c.
| bool qhashtbl_putstrf | ( | qhashtbl_t * | tbl, |
| const char * | name, | ||
| const char * | format, | ||
| ... ) |
qhashtbl->putstrf(): Put a formatted string into this table.
| tbl | qhashtbl_t container pointer. |
| name | key name. |
| format | formatted string data. |
| errno | will be set in error condition.
|
Definition at line 295 of file qhashtbl.c.
| bool qhashtbl_putint | ( | qhashtbl_t * | tbl, |
| const char * | name, | ||
| const int64_t | num ) |
qhashtbl->putint(): Put an integer into this table as a string.
| tbl | qhashtbl_t container pointer. |
| name | key name. |
| num | integer data. |
| errno | will be set in error condition.
|
Definition at line 323 of file qhashtbl.c.
| void * qhashtbl_get | ( | qhashtbl_t * | tbl, |
| const char * | name, | ||
| size_t * | size, | ||
| bool | newmem ) |
qhashtbl->get(): Get an object from this table.
| tbl | qhashtbl_t container pointer. |
| name | key name. |
| size | if not NULL, object size will be stored. |
| newmem | whether or not to allocate memory for the data. |
| errno | will be set in error condition.
|
Definition at line 363 of file qhashtbl.c.
| char * qhashtbl_getstr | ( | qhashtbl_t * | tbl, |
| const char * | name, | ||
| const bool | newmem ) |
qhashtbl->getstr(): Finds an object and returns it as a string.
| tbl | qhashtbl_t container pointer. |
| name | key name |
| newmem | whether or not to allocate memory for the data. |
| errno | will be set in error condition.
|
Definition at line 422 of file qhashtbl.c.
| int64_t qhashtbl_getint | ( | qhashtbl_t * | tbl, |
| const char * | name ) |
qhashtbl->getint(): Finds an object with given name and returns as integer type.
| tbl | qhashtbl_t container pointer. |
| name | key name |
| errno | will be set in error condition.
|
Definition at line 439 of file qhashtbl.c.
| bool qhashtbl_remove | ( | qhashtbl_t * | tbl, |
| const char * | name ) |
qhashtbl->remove(): Remove an object from this table.
| tbl | qhashtbl_t container pointer. |
| name | key name |
| errno | will be set in error condition.
|
Definition at line 461 of file qhashtbl.c.
| bool qhashtbl_getnext | ( | qhashtbl_t * | tbl, |
| qhashtbl_obj_t * | obj, | ||
| const bool | newmem ) |
qhashtbl->getnext(): Get next element.
| tbl | qhashtbl_t container pointer. |
| obj | found data will be stored in this object |
| newmem | whether or not to allocate memory for the data. |
| errno | will be set in error condition.
|
Definition at line 543 of file qhashtbl.c.
| size_t qhashtbl_size | ( | qhashtbl_t * | tbl | ) |
qhashtbl->size(): Returns the number of keys in this hashtable.
| tbl | qhashtbl_t container pointer. |
Definition at line 613 of file qhashtbl.c.
| void qhashtbl_clear | ( | qhashtbl_t * | tbl | ) |
qhashtbl->clear(): Clears this hashtable so that it contains no keys.
| tbl | qhashtbl_t container pointer. |
Definition at line 622 of file qhashtbl.c.
| bool qhashtbl_debug | ( | qhashtbl_t * | tbl, |
| FILE * | out ) |
qhashtbl->debug(): Print the hash table for debugging purposes.
| tbl | qhashtbl_t container pointer. |
| out | output stream such as stdout or stderr. |
| errno | will be set in error condition.
|
Definition at line 654 of file qhashtbl.c.
| void qhashtbl_lock | ( | qhashtbl_t * | tbl | ) |
qhashtbl->lock(): Enter critical section.
| tbl | qhashtbl_t container pointer. |
Definition at line 686 of file qhashtbl.c.
| void qhashtbl_unlock | ( | qhashtbl_t * | tbl | ) |
qhashtbl->unlock(): Leave critical section.
| tbl | qhashtbl_t container pointer. |
Definition at line 699 of file qhashtbl.c.
| void qhashtbl_free | ( | qhashtbl_t * | tbl | ) |
qhashtbl->free(): Free hash table
| tbl | qhashtbl_t container pointer. |
Definition at line 708 of file qhashtbl.c.