qLibc
|
Linked-list-table implementation. More...
Go to the source code of this file.
Functions | |
qlisttbl_t * | qlisttbl (int options) |
Create a new Q_LIST linked-list container. | |
bool | qlisttbl_put (qlisttbl_t *tbl, const char *name, const void *data, size_t size) |
qlisttbl->put(): Put an element to this table. | |
bool | qlisttbl_putstr (qlisttbl_t *tbl, const char *name, const char *str) |
qlisttbl->putstr(): Put a string into this table. | |
bool | qlisttbl_putstrf (qlisttbl_t *tbl, const char *name, const char *format,...) |
qlisttbl->putstrf(): Put a formatted string into this table. | |
bool | qlisttbl_putint (qlisttbl_t *tbl, const char *name, int64_t num) |
qlisttbl->putInt(): Put an integer into this table as string type. | |
void * | qlisttbl_get (qlisttbl_t *tbl, const char *name, size_t *size, bool newmem) |
qlisttbl->get(): Finds an object with given name. | |
char * | qlisttbl_getstr (qlisttbl_t *tbl, const char *name, bool newmem) |
qlisttbl->getstr(): Finds an object with given name and returns as string type. | |
int64_t | qlisttbl_getint (qlisttbl_t *tbl, const char *name) |
qlisttbl->getint(): Finds an object with given name and returns as integer type. | |
qlisttbl_data_t * | qlisttbl_getmulti (qlisttbl_t *tbl, const char *name, bool newmem, size_t *numobjs) |
qlisttbl->getmulti(): Finds all objects with given name and return a array of objects. | |
void | qlisttbl_freemulti (qlisttbl_data_t *objs) |
qlisttbl->freemulti(): Deallocate object array returned by getmulti(). | |
size_t | qlisttbl_remove (qlisttbl_t *tbl, const char *name) |
qlisttbl->remove(): Remove matched objects with given name. | |
bool | qlisttbl_removeobj (qlisttbl_t *tbl, const qlisttbl_obj_t *obj) |
qlisttbl->removeobj(): Remove objects with given object pointer. | |
bool | qlisttbl_getnext (qlisttbl_t *tbl, qlisttbl_obj_t *obj, const char *name, bool newmem) |
qlisttbl->getnext(): Get next element. | |
size_t | qlisttbl_size (qlisttbl_t *tbl) |
qlisttbl->size(): Returns the number of elements in this table. | |
void | qlisttbl_sort (qlisttbl_t *tbl) |
qlisttbl->sort(): Sort keys in this table. | |
void | qlisttbl_clear (qlisttbl_t *tbl) |
qlisttbl->clear(): Removes all of the elements from this table. | |
bool | qlisttbl_save (qlisttbl_t *tbl, const char *filepath, char sepchar, bool encode) |
qlisttbl->save(): Save qlisttbl as plain text format Dumping direction is always forward(from the top to the bottom) to preserve the order when we load the file again. | |
ssize_t | qlisttbl_load (qlisttbl_t *tbl, const char *filepath, char sepchar, bool decode) |
qlisttbl->load(): Load and append entries from given filepath Loading direction is always appending at the bottom of the table to preserve the order as it was. | |
bool | qlisttbl_debug (qlisttbl_t *tbl, FILE *out) |
qlisttbl->debug(): Print out stored elements for debugging purpose. | |
void | qlisttbl_lock (qlisttbl_t *tbl) |
qlisttbl->lock(): Enter critical section. | |
void | qlisttbl_unlock (qlisttbl_t *tbl) |
qlisttbl->unlock(): Leave critical section. | |
void | qlisttbl_free (qlisttbl_t *tbl) |
qlisttbl->free(): Free qlisttbl_t | |
Linked-list-table implementation.
qlisttbl container is a Linked-List-Table implementation. Which maps keys to values. Key is a string and value is any non-null object. These elements are stored sequentially in Doubly-Linked-List data structure.
Compared to Hash-Table, List-Table is efficient when you need to keep duplicated keys since Hash-Table only keep unique keys. Of course, qlisttbl supports both unique keys and key duplication.
Definition in file qlisttbl.c.
qlisttbl_t * qlisttbl | ( | int | options | ) |
Create a new Q_LIST linked-list container.
options | combination of initialization options. |
errno | will be set in error condition.
|
Definition at line 150 of file qlisttbl.c.
bool qlisttbl_put | ( | qlisttbl_t * | tbl, |
const char * | name, | ||
const void * | data, | ||
size_t | size | ||
) |
qlisttbl->put(): Put an element to this table.
tbl | qlisttbl container pointer. |
name | element name. |
data | a pointer which points data memory. |
size | size of the data. |
errno | will be set in error condition.
|
Definition at line 249 of file qlisttbl.c.
bool qlisttbl_putstr | ( | qlisttbl_t * | tbl, |
const char * | name, | ||
const char * | str | ||
) |
qlisttbl->putstr(): Put a string into this table.
tbl | qlisttbl container pointer. |
name | element name. |
str | string data. |
errno | will be set in error condition.
|
Definition at line 296 of file qlisttbl.c.
bool qlisttbl_putstrf | ( | qlisttbl_t * | tbl, |
const char * | name, | ||
const char * | format, | ||
... | |||
) |
qlisttbl->putstrf(): Put a formatted string into this table.
tbl | qlisttbl container pointer. |
name | element name. |
format | formatted value string. |
errno | will be set in error condition.
|
Definition at line 314 of file qlisttbl.c.
bool qlisttbl_putint | ( | qlisttbl_t * | tbl, |
const char * | name, | ||
int64_t | num | ||
) |
qlisttbl->putInt(): Put an integer into this table as string type.
tbl | qlisttbl container pointer. |
name | element name. |
num | number data. |
errno | will be set in error condition.
|
Definition at line 345 of file qlisttbl.c.
void * qlisttbl_get | ( | qlisttbl_t * | tbl, |
const char * | name, | ||
size_t * | size, | ||
bool | newmem | ||
) |
qlisttbl->get(): Finds an object with given name.
If there are duplicate keys in the table, this will return the first matched one from the bottom (or the top if QLISTTBL_LOOKUPFORWARD option was given). So if there are duplicated keys, it'll return recently inserted one.
tbl | qlisttbl container pointer. |
name | element name. |
size | if size is not NULL, data size will be stored. |
newmem | whether or not to allocate memory for the data. |
errno | will be set in error condition.
|
Definition at line 392 of file qlisttbl.c.
char * qlisttbl_getstr | ( | qlisttbl_t * | tbl, |
const char * | name, | ||
bool | newmem | ||
) |
qlisttbl->getstr(): Finds an object with given name and returns as string type.
tbl | qlisttbl container pointer. |
name | element name. |
newmem | whether or not to allocate memory for the data. |
errno | will be set in error condition.
|
Definition at line 442 of file qlisttbl.c.
int64_t qlisttbl_getint | ( | qlisttbl_t * | tbl, |
const char * | name | ||
) |
qlisttbl->getint(): Finds an object with given name and returns as integer type.
tbl | qlisttbl container pointer. |
name | element name. |
errno | will be set in error condition.
|
Definition at line 460 of file qlisttbl.c.
qlisttbl_data_t * qlisttbl_getmulti | ( | qlisttbl_t * | tbl, |
const char * | name, | ||
bool | newmem, | ||
size_t * | numobjs | ||
) |
qlisttbl->getmulti(): Finds all objects with given name and return a array of objects.
If there are duplicate keys in the table, this will return all the matched ones. The order of objects in return depends on setnextdir() setting. By default, the order is same(forward) as listed in the table.
tbl | qlisttbl container pointer. |
name | element name. |
newmem | whether or not to allocate memory for the data. |
numobjs | the nuber of objects returned will be stored. (can be NULL) |
errno | will be set in error condition.
|
Definition at line 504 of file qlisttbl.c.
void qlisttbl_freemulti | ( | qlisttbl_data_t * | objs | ) |
qlisttbl->freemulti(): Deallocate object array returned by getmulti().
objs | pointer of array of qlisttbl_data_t. |
Definition at line 573 of file qlisttbl.c.
size_t qlisttbl_remove | ( | qlisttbl_t * | tbl, |
const char * | name | ||
) |
qlisttbl->remove(): Remove matched objects with given name.
tbl | qlisttbl container pointer. |
name | element name. |
Definition at line 593 of file qlisttbl.c.
bool qlisttbl_removeobj | ( | qlisttbl_t * | tbl, |
const qlisttbl_obj_t * | obj | ||
) |
qlisttbl->removeobj(): Remove objects with given object pointer.
This call is useful when you want to remove an element while traversing a table using getnext(). So the address pointed by obj maybe different than the actual object in a table, but it's ok because we'll recalculate the actual object address by referring it's links.
tbl | qlisttbl container pointer. |
name | element name. |
errno | will be set in error condition.
|
Definition at line 636 of file qlisttbl.c.
bool qlisttbl_getnext | ( | qlisttbl_t * | tbl, |
qlisttbl_obj_t * | obj, | ||
const char * | name, | ||
bool | newmem | ||
) |
qlisttbl->getnext(): Get next element.
Default searching direction is backward, from the bottom to top unless QLISTTBL_LOOKUPFORWARD option was specified.
tbl | qlisttbl container pointer. |
obj | found data will be stored in this object |
name | element name., if key name is NULL search every objects in the table. |
newmem | whether or not to allocate memory for the data. |
errno | will be set in error condition.
|
Definition at line 727 of file qlisttbl.c.
size_t qlisttbl_size | ( | qlisttbl_t * | tbl | ) |
qlisttbl->size(): Returns the number of elements in this table.
tbl | qlisttbl container pointer. |
Definition at line 799 of file qlisttbl.c.
void qlisttbl_sort | ( | qlisttbl_t * | tbl | ) |
qlisttbl->sort(): Sort keys in this table.
tbl | qlisttbl container pointer. |
Definition at line 826 of file qlisttbl.c.
void qlisttbl_clear | ( | qlisttbl_t * | tbl | ) |
qlisttbl->clear(): Removes all of the elements from this table.
tbl | qlisttbl container pointer. |
Definition at line 862 of file qlisttbl.c.
bool qlisttbl_save | ( | qlisttbl_t * | tbl, |
const char * | filepath, | ||
char | sepchar, | ||
bool | encode | ||
) |
qlisttbl->save(): Save qlisttbl as plain text format Dumping direction is always forward(from the top to the bottom) to preserve the order when we load the file again.
tbl | qlisttbl container pointer. |
filepath | save file path |
sepchar | separator character between name and value. normally '=' is used. |
encode | flag for encoding data . false can be used if the all data are string or integer type and has no new line. otherwise true must be set. |
Definition at line 895 of file qlisttbl.c.
ssize_t qlisttbl_load | ( | qlisttbl_t * | tbl, |
const char * | filepath, | ||
char | sepchar, | ||
bool | decode | ||
) |
qlisttbl->load(): Load and append entries from given filepath Loading direction is always appending at the bottom of the table to preserve the order as it was.
tbl | qlisttbl container pointer. |
filepath | save file path |
sepchar | separator character between name and value. normally '=' is used |
decode | flag for decoding data |
Definition at line 941 of file qlisttbl.c.
bool qlisttbl_debug | ( | qlisttbl_t * | tbl, |
FILE * | out | ||
) |
qlisttbl->debug(): Print out stored elements for debugging purpose.
tbl | qlisttbl container pointer. |
out | output stream FILE descriptor such like stdout, stderr. |
errno | will be set in error condition.
|
Definition at line 993 of file qlisttbl.c.
void qlisttbl_lock | ( | qlisttbl_t * | tbl | ) |
qlisttbl->lock(): Enter critical section.
tbl | qlisttbl container pointer. |
Definition at line 1021 of file qlisttbl.c.
void qlisttbl_unlock | ( | qlisttbl_t * | tbl | ) |
qlisttbl->unlock(): Leave critical section.
tbl | qlisttbl container pointer. |
Definition at line 1031 of file qlisttbl.c.
void qlisttbl_free | ( | qlisttbl_t * | tbl | ) |
qlisttbl->free(): Free qlisttbl_t
tbl | qlisttbl container pointer. |
Definition at line 1041 of file qlisttbl.c.