Lists for storing items, and can grow unlimited.
More...
|
| #define | ci_list_first(list) (list && (list)->items && (((list)->cursor = (list)->items->next) != NULL || 1) ? (list)->items->item : NULL) |
| | Gets the first item of the list and updates the list cursor to the next item. More...
|
| |
| #define | ci_list_next(list) (((list)->tmp = (list)->cursor) != NULL && (((list)->cursor = (list)->cursor->next) != NULL || 1) ? (list)->tmp->item : NULL) |
| | Return the next item of the list and updates the list cursor to the next item. More...
|
| |
|
#define | ci_list_head(list) (list && list->items != NULL ? list->items->item : NULL) |
| | Return the head of the list.
|
| |
|
#define | ci_list_tail(list) (list && list->last != NULL ? list->last->item : NULL) |
| | Return last item of the list.
|
| |
|
| typedef struct ci_list | ci_list_t |
| | The ci_list_t objects can store a list of objects, with a predefined size. More...
|
| |
|
| ci_list_t * | ci_list_create (size_t init_size, size_t obj_size) |
| | Allocate the required memory and initialize a ci_list_t object. More...
|
| |
| void | ci_list_destroy (ci_list_t *list) |
| | Destroy an ci_list_t object. More...
|
| |
| void | ci_list_iterate (ci_list_t *list, void *data, int(*fn)(void *data, const void *obj)) |
| | Run the given function for each list item. More...
|
| |
| const void * | ci_list_push (ci_list_t *list, const void *obj) |
| | Add an item to the head of list. More...
|
| |
| const void * | ci_list_push_back (ci_list_t *list, const void *data) |
| | Add an item to the tail of list. More...
|
| |
| void * | ci_list_pop (ci_list_t *list, void *obj) |
| | Remove the first item of the list. More...
|
| |
| void * | ci_list_pop_back (ci_list_t *list, void *obj) |
| | Remove the last item of the list. More...
|
| |
| int | ci_list_remove (ci_list_t *list, const void *obj) |
| | Remove the first found item equal to the obj. More...
|
| |
| const void * | ci_list_search (ci_list_t *list, const void *data) |
| | Return the first found item equal to the obj. More...
|
| |
| const void * | ci_list_search2 (ci_list_t *list, const void *data, int(*cmp_func)(const void *obj, const void *user_data, size_t user_data_size)) |
| | Return the first found item equal to the obj, using the cmp_func as comparison function. More...
|
| |
| void | ci_list_sort (ci_list_t *list) |
| | Sorts the list using as compare function the default. More...
|
| |
| void | ci_list_sort2 (ci_list_t *list, int(*cmp_func)(const void *obj1, const void *obj2, size_t obj_size)) |
| | Sorts the list using as compare function the cmp_func. More...
|
| |
Lists for storing items, and can grow unlimited.
| #define ci_list_first |
( |
|
list | ) |
(list && (list)->items && (((list)->cursor = (list)->items->next) != NULL || 1) ? (list)->items->item : NULL) |
Gets the first item of the list and updates the list cursor to the next item.
WARNING: do not mix this macro with ci_list_iterate. Use the ci_list_head and ci_list_tail macros instead
- Parameters
-
| list | a pointer to the ci_list_t object |
- Returns
- The first item if exist, NULL otherwise
| #define ci_list_next |
( |
|
list | ) |
(((list)->tmp = (list)->cursor) != NULL && (((list)->cursor = (list)->cursor->next) != NULL || 1) ? (list)->tmp->item : NULL) |
Return the next item of the list and updates the list cursor to the next item.
WARNING: It does not check for valid list object. WARNING: do not mix this macro with ci_list_iterate!
- Parameters
-
| list | a pointer to the ci_list_t object |
- Returns
- The next item if exist, NULL otherwise
The ci_list_t objects can store a list of objects, with a predefined size.
The list items can be removed. The memory RAM space of list can not be decreased before the ci_list destroyed. However the memory of removed items reused.
| ci_list_t* ci_list_create |
( |
size_t |
init_size, |
|
|
size_t |
obj_size |
|
) |
| |
Allocate the required memory and initialize a ci_list_t object.
- Parameters
-
| init_size | the initial memory size to use |
| obj_size | the size of stored objects. If it is 0 then stores pointers to objects. |
- Returns
- the allocated object on success, or NULL on failure
Destroy an ci_list_t object.
- Parameters
-
| list | a pointer to ci_list_t object to be destroyed |
| void ci_list_iterate |
( |
ci_list_t * |
list, |
|
|
void * |
data, |
|
|
int(*)(void *data, const void *obj) |
fn |
|
) |
| |
Run the given function for each list item.
- Parameters
-
| list | a pointer to the ci_list_t object |
| data | a pointer to data which will be passed to the fn function |
| fn | a pointer to the function which will be run for each vector item. The iteration will stop if the fn function return non zero value. |
| void* ci_list_pop |
( |
ci_list_t * |
list, |
|
|
void * |
obj |
|
) |
| |
Remove the first item of the list.
- Parameters
-
| list | a pointer to the ci_list_t object |
| obj | pointer to an object to store removed item |
- Returns
- a pointer to the obj on success, NULL otherwise
| void* ci_list_pop_back |
( |
ci_list_t * |
list, |
|
|
void * |
obj |
|
) |
| |
Remove the last item of the list.
- Parameters
-
| list | a pointer to the ci_list_t object |
| obj | pointer to an object to store removed item |
- Returns
- a pointer to the obj on success, NULL otherwise
| const void* ci_list_push |
( |
ci_list_t * |
list, |
|
|
const void * |
obj |
|
) |
| |
Add an item to the head of list.
- Parameters
-
| list | a pointer to the ci_list_t object |
| obj | pointer to the object to add in vector |
- Returns
- a pointer to the new item on success, NULL otherwise
| const void* ci_list_push_back |
( |
ci_list_t * |
list, |
|
|
const void * |
data |
|
) |
| |
Add an item to the tail of list.
- Parameters
-
| list | a pointer to the ci_list_t object |
| obj | pointer to the object to add in vector |
- Returns
- a pointer to the new item on success, NULL otherwise
| int ci_list_remove |
( |
ci_list_t * |
list, |
|
|
const void * |
obj |
|
) |
| |
Remove the first found item equal to the obj.
- Parameters
-
| list | a pointer to the ci_list_t object |
| obj | pointer to an object to remove |
- Returns
- not 0 on success, 0 otherwise
| const void* ci_list_search |
( |
ci_list_t * |
list, |
|
|
const void * |
data |
|
) |
| |
Return the first found item equal to the obj.
- Parameters
-
| list | a pointer to the ci_list_t object |
| obj | pointer to an object to remove |
- Returns
- the found item on success, NULL otherwise
| const void* ci_list_search2 |
( |
ci_list_t * |
list, |
|
|
const void * |
data, |
|
|
int(*)(const void *obj, const void *user_data, size_t user_data_size) |
cmp_func |
|
) |
| |
Return the first found item equal to the obj, using the cmp_func as comparison function.
- Parameters
-
| list | a pointer to the ci_list_t object |
| obj | pointer to an object to remove |
| cmp_func | the comparison function to use |
- Returns
- the found item on success, NULL otherwise
Sorts the list using as compare function the default.
- Parameters
-
| list | a pointer to the ci_list_t object |
| void ci_list_sort2 |
( |
ci_list_t * |
list, |
|
|
int(*)(const void *obj1, const void *obj2, size_t obj_size) |
cmp_func |
|
) |
| |
Sorts the list using as compare function the cmp_func.
- Parameters
-
| list | a pointer to the ci_list_t object |
| cmp_func | the compare function to use |