![]() |
Functions | |
Q_HASHTBL * | qHashtbl (int max, bool resize, int threshold) |
Initialize dynamic-hash table. | |
static void | _lock (Q_HASHTBL *tbl) |
Q_HASHtbl->lock(): Enter critical section. | |
static void | _unlock (Q_HASHTBL *tbl) |
Q_HASHTBL->unlock(): Leave critical section. | |
static bool | _put (Q_HASHTBL *tbl, const char *name, const void *data, size_t size) |
Q_HASHTBL->put(): Put object into hash table. | |
static bool | _putStr (Q_HASHTBL *tbl, const char *name, const char *str) |
Q_HASHTBL->putStr(): Put string into hash table. | |
static bool | _putInt (Q_HASHTBL *tbl, const char *name, const int num) |
Q_HASHTBL->putInt(): Put integer into hash table. | |
static void * | _get (Q_HASHTBL *tbl, const char *name, size_t *size, bool newmem) |
Q_HASHTBL->get(): Get object from hash table. | |
static char * | _getStr (Q_HASHTBL *tbl, const char *name, bool newmem) |
Q_HASHTBL->getStr(): Get string from hash table. | |
static int | _getInt (Q_HASHTBL *tbl, const char *name) |
Q_HASHTBL->getInt(): Get integer from hash table. | |
static bool | _getNext (Q_HASHTBL *tbl, Q_NOBJ_T *obj, int *idx, bool newmem) |
Q_HASHTBL->getNext(): Get next key name. | |
static bool | _remove (Q_HASHTBL *tbl, const char *name) |
Q_HASHTBL->remove(): Remove key from hash table. | |
static int | _getNum (Q_HASHTBL *tbl) |
Q_HASHTBL->getNum(): get number of objects stored. | |
static int | _getMax (Q_HASHTBL *tbl) |
Q_HASHTBL->getMax(): Get number of object slots. | |
bool | _truncate (Q_HASHTBL *tbl) |
Q_HASHTBL->truncate(): Truncate hash table. | |
bool | _resize (Q_HASHTBL *tbl, int max) |
Q_HASHTBL->resize(): Resize dynamic-hash table. | |
bool | _print (Q_HASHTBL *tbl, FILE *out, bool print_data) |
Q_HASHTBL->print(): Print hash table for debugging purpose. | |
bool | _free (Q_HASHTBL *tbl) |
Q_HASHTBL->free(): De-allocate hash table. |
Q_HASHTBL* qHashtbl | ( | int | max, | |
bool | resize, | |||
int | threshold | |||
) |
Initialize dynamic-hash table.
max | a number of initial number of slots of Q_HASHTBL | |
resize | enable or disable auto incremental resizing | |
threshold | a persent of threshold for resizing. 0 for default. |
// initial table size is 1000, enable resizing, use default threshold Q_HASHTBL *hashtbl = qHashtblInit(1000, true, 0); qHashtblFree(hashtbl);
static void _lock | ( | Q_HASHTBL * | tbl | ) | [static] |
Q_HASHtbl->lock(): Enter critical section.
static void _unlock | ( | Q_HASHTBL * | tbl | ) | [static] |
Q_HASHTBL->unlock(): Leave critical section.
static bool _put | ( | Q_HASHTBL * | tbl, | |
const char * | name, | |||
const void * | data, | |||
size_t | size | |||
) | [static] |
Q_HASHTBL->put(): Put object into hash table.
tbl | a pointer of Q_HASHTBL | |
name | key name | |
data | data object | |
size | size of data object |
static bool _putStr | ( | Q_HASHTBL * | tbl, | |
const char * | name, | |||
const char * | str | |||
) | [static] |
Q_HASHTBL->putStr(): Put string into hash table.
tbl | a pointer of Q_HASHTBL | |
name | key name | |
data | data object |
static bool _putInt | ( | Q_HASHTBL * | tbl, | |
const char * | name, | |||
const int | num | |||
) | [static] |
Q_HASHTBL->putInt(): Put integer into hash table.
tbl | a pointer of Q_HASHTBL | |
name | key name | |
data | data object |
static void* _get | ( | Q_HASHTBL * | tbl, | |
const char * | name, | |||
size_t * | size, | |||
bool | newmem | |||
) | [static] |
Q_HASHTBL->get(): Get object from hash table.
tbl | a pointer of Q_HASHTBL | |
name | key name | |
size | if not NULL, oject size will be stored | |
newmem | whether or not to allocate memory for the data. |
Q_HASHTBL *tbl = qHashtbl(); (...codes...) // with newmem flag unset size_t size; const char *data = tbl->get(tbl, "key_name", &size, false); // with newmem flag set size_t size; char *data = tbl->get(tbl, "key_name", &size, true); if(data != NULL) free(data);
static char* _getStr | ( | Q_HASHTBL * | tbl, | |
const char * | name, | |||
bool | newmem | |||
) | [static] |
Q_HASHTBL->getStr(): Get string from hash table.
tbl | a pointer of Q_HASHTBL | |
name | key name | |
newmem | whether or not to allocate memory for the data. |
static int _getInt | ( | Q_HASHTBL * | tbl, | |
const char * | name | |||
) | [static] |
Q_HASHTBL->getInt(): Get integer from hash table.
tbl | a pointer of Q_HASHTBL | |
name | key name |
Q_HASHTBL->getNext(): Get next key name.
tbl | a pointer of Q_HASHTBL | |
idx | index pointer (must be set to 0 when first call) |
Q_HASHTBL *tbl = qHashtbl(); tbl->putStr(tbl, "key1", "hello world 1", false); tbl->putStr(tbl, "key2", "hello world 2", false); tbl->putStr(tbl, "key3", "hello world 3", false); // non-thread usages int idx = 0; Q_NOBJ_T obj; while(tbl->getNext(tbl, &obj, &idx, false) == true) { printf("NAME=%s, DATA=%s", SIZE=%zu", obj.name, obj.data, obj.size); } // thread model int idx = 0; Q_NOBJ_T obj; tbl->lock(); while(tbl->getNext(tbl, &obj, &idx, false) == true) { printf("NAME=%s, DATA=%s", SIZE=%zu", obj.name, obj.data, obj.size); } tbl->unlock(); // thread model 2 with newmem flag int idx = 0; Q_NOBJ_T obj; tbl->lock(); while(tbl->getNext(tbl, &obj, &idx, false) == true) { printf("NAME=%s, DATA=%s", SIZE=%zu", obj.name, obj.data, obj.size); free(obj.name); free(obj.data); } tbl->unlock();
static bool _remove | ( | Q_HASHTBL * | tbl, | |
const char * | name | |||
) | [static] |
Q_HASHTBL->remove(): Remove key from hash table.
tbl | a pointer of Q_HASHTBL | |
name | key name |
static int _getNum | ( | Q_HASHTBL * | tbl | ) | [static] |
Q_HASHTBL->getNum(): get number of objects stored.
tbl | a pointer of Q_HASHTBL |
static int _getMax | ( | Q_HASHTBL * | tbl | ) | [static] |
Q_HASHTBL->getMax(): Get number of object slots.
tbl | a pointer of Q_HASHTBL |
bool _truncate | ( | Q_HASHTBL * | tbl | ) |
Q_HASHTBL->truncate(): Truncate hash table.
tbl | a pointer of Q_HASHTBL |
bool _resize | ( | Q_HASHTBL * | tbl, | |
int | max | |||
) |
Q_HASHTBL->resize(): Resize dynamic-hash table.
tbl | a pointer of Q_HASHTBL | |
max | a number of initial number of slots of Q_HASHTBL |
// initial table size is 1000, enable resizing, use default threshold
qHashtblResize(tbl, 3000);
bool _print | ( | Q_HASHTBL * | tbl, | |
FILE * | out, | |||
bool | print_data | |||
) |
Q_HASHTBL->print(): Print hash table for debugging purpose.
tbl | a pointer of Q_HASHTBL | |
out | output stream | |
print_data | print out value if set to true |
bool _free | ( | Q_HASHTBL * | tbl | ) |
Q_HASHTBL->free(): De-allocate hash table.
tbl | a pointer of Q_HASHTBL |