|
qlist_t * | qlist (int options) |
| Create new qlist_t linked-list container. More...
|
|
size_t | qlist_setsize (qlist_t *list, size_t max) |
| qlist->setsize(): Limit maximum number of elements allowed in this list. More...
|
|
bool | qlist_addfirst (qlist_t *list, const void *data, size_t size) |
| qlist->addfirst(): Inserts a element at the beginning of this list. More...
|
|
bool | qlist_addlast (qlist_t *list, const void *data, size_t size) |
| qlist->addlast(): Appends a element to the end of this list. More...
|
|
bool | qlist_addat (qlist_t *list, int index, const void *data, size_t size) |
| qlist->addat(): Inserts a element at the specified position in this list. More...
|
|
void * | qlist_getfirst (qlist_t *list, size_t *size, bool newmem) |
| qlist->getfirst(): Returns the first element in this list. More...
|
|
void * | qlist_getlast (qlist_t *list, size_t *size, bool newmem) |
| qlist->getlast(): Returns the last element in this list. More...
|
|
void * | qlist_getat (qlist_t *list, int index, size_t *size, bool newmem) |
| qlist->getat(): Returns the element at the specified position in this list. More...
|
|
void * | qlist_popfirst (qlist_t *list, size_t *size) |
| qlist->popfirst(): Returns and remove the first element in this list. More...
|
|
void * | qlist_poplast (qlist_t *list, size_t *size) |
| qlist->getlast(): Returns and remove the last element in this list. More...
|
|
void * | qlist_popat (qlist_t *list, int index, size_t *size) |
| qlist->popat(): Returns and remove the element at the specified position in this list. More...
|
|
bool | qlist_removefirst (qlist_t *list) |
| qlist->removefirst(): Removes the first element in this list. More...
|
|
bool | qlist_removelast (qlist_t *list) |
| qlist->removelast(): Removes the last element in this list. More...
|
|
bool | qlist_removeat (qlist_t *list, int index) |
| qlist->removeat(): Removes the element at the specified position in this list. More...
|
|
bool | qlist_getnext (qlist_t *list, qlist_obj_t *obj, bool newmem) |
| qlist->getnext(): Get next element in this list. More...
|
|
size_t | qlist_size (qlist_t *list) |
| qlist->size(): Returns the number of elements in this list. More...
|
|
size_t | qlist_datasize (qlist_t *list) |
| qlist->size(): Returns the sum of total element size. More...
|
|
void | qlist_reverse (qlist_t *list) |
| qlist->reverse(): Reverse the order of elements. More...
|
|
void | qlist_clear (qlist_t *list) |
| qlist->clear(): Removes all of the elements from this list. More...
|
|
void * | qlist_toarray (qlist_t *list, size_t *size) |
| qlist->toarray(): Returns the serialized chunk containing all the elements in this list. More...
|
|
char * | qlist_tostring (qlist_t *list) |
| qlist->tostring(): Returns a string representation of this list, containing string representation of each element. More...
|
|
bool | qlist_debug (qlist_t *list, FILE *out) |
| qlist->debug(): Prints out stored elements for debugging purpose. More...
|
|
void | qlist_lock (qlist_t *list) |
| qlist->lock(): Enters critical section. More...
|
|
void | qlist_unlock (qlist_t *list) |
| qlist->unlock(): Leaves critical section. More...
|
|
void | qlist_free (qlist_t *list) |
| qlist->free(): Free qlist_t. More...
|
|
Doubly Linked-list implementation.
qlist container is a doubly Linked-List implementation. qlist provides uniformly named methods to add, get, pop and remove an element at the beginning and end of the list. These operations allow qlist to be used as a stack, queue, or double-ended queue.
[Conceptional Data Structure Diagram]
last~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~+
|
+-----------+ doubly +-----------+ doubly +-|---------+
first~~~|~> 0 <~|~~~~~~~~~~|~> 1 <~|~~~~~~~~~~|~> N |
+-----|-----+ linked +-----|-----+ linked +-----|-----+
| | |
+-----v---------------+ | +-----v-----+
| DATA A | | | DATA N |
+---------------------+ | +-----------+
+---------------------v------------------+
| DATA B |
+----------------------------------------+
qlist_t *list =
qlist(QLIST_THREADSAFE);
list->addlast(list, "e1", sizeof("e1"));
list->addlast(list, "e2", sizeof("e2"));
list->addlast(list, "e3", sizeof("e3"));
char *e1 = (char*)list->getfirst(list, NULL, true));
char *e3 = (char*)list->getat(list, -1, NULL, false));
(...omit...)
free(e1);
char *e2 = (char*)list->popat(list, 1, NULL));
(...omit...)
free(e2);
list->debug(list, stdout, true);
qlist_obj_t obj;
memset((void*)&obj, 0, sizeof(obj));
list->lock(list);
while (list->getnext(list, &obj, false) == true) {
printf("DATA=%s, SIZE=%zu\n", (char*)obj.data, obj.size);
}
list->unlock(list);
list->free(list);
Definition in file qlist.c.