18LIST* new_generic_list(
size_t max_items) {
70 if (node->
prev == NULL && node->
next) {
74 if (node->
prev && node->
next == NULL) {
78 if (node->
prev == NULL && node->
next == NULL) {
152 nodeptr = list->
start;
233int list_push_sorted(
LIST* list,
void* ptr,
int (*comparator)(
const void* a,
const void* b),
void (*destructor)(
void* ptr)) {
247 while (nodeptr && (comparator(ptr, nodeptr->
ptr) < 0))
248 nodeptr = nodeptr->
prev;
254 n_log(
LOG_ERR,
"Couldn't list_unshift in list %p ptr %p with destructor %p", list, ptr, destructor);
274 n_log(
LOG_ERR,
"Couldn't list_push in list %p ptr %p with destructor %p", list, ptr, destructor);
321int list_unshift_sorted(
LIST* list,
void* ptr,
int (*comparator)(
const void* a,
const void* b),
void (*destructor)(
void* ptr)) {
334 nodeptr = list->
start;
335 while (nodeptr && (comparator(ptr, nodeptr->ptr) > 0))
336 nodeptr = nodeptr->
next;
342 n_log(
LOG_ERR,
"Couldn't list_push in list %p ptr %p with destructor %p", list, ptr, destructor);
354 list->
start = newnode;
362 n_log(
LOG_ERR,
"Couldn't list_unshift in list %p ptr %p with destructor %p", list, ptr, destructor);
416 nodeptr = list->
start;
444 if (node->ptr == ptr)
460 if (checkfunk(node->ptr))
472 LIST_NODE *node = NULL, *node_ptr = NULL;
480 if (node_ptr->destroy_func != NULL) {
497 LIST_NODE *node = NULL, *node_ptr = NULL;
505 free_fnct(node_ptr->ptr);
#define Malloc(__ptr, __struct, __size)
Malloc Handler to get errors and set to 0.
#define __n_assert(__ptr, __ret)
macro to assert things
#define Free(__ptr)
Free Handler to get errors.
LIST_NODE * end
pointer to the end of the list
void * ptr
void pointer to store
size_t nb_max_items
maximum number of item in the list.
struct LIST_NODE * prev
pointer to the previous node
LIST_NODE * start
pointer to the start of the list
size_t nb_items
number of item currently in the list
void(* destroy_func)(void *ptr)
pointer to destructor function if any, else NULL
struct LIST_NODE * next
pointer to the next node
void * list_pop_f(LIST *list)
Get a pointer from the end of the list.
void * list_shift_f(LIST *list, char *file, size_t line)
Get a pointer from the start of the list.
int list_empty(LIST *list)
Empty a LIST list of pointers.
int list_push(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer to the end of the list.
int list_node_unshift(LIST *list, LIST_NODE *node)
Add a pointer at the start of the list.
#define list_foreach(__ITEM_, __LIST_)
ForEach macro helper.
int list_unshift(LIST *list, void *ptr, void(*destructor)(void *ptr))
Add a pointer at the start of the list.
LIST_NODE * list_node_shift(LIST *list)
Get a LIST_NODE pointer from the start of the list.
LIST_NODE * new_list_node(void *ptr, void(*destructor)(void *ptr))
Allocate a new node to link in a list.
#define link_node(__NODE_1, __NODE_2)
Macro helper for linking two nodes.
int list_destroy(LIST **list)
Empty and Free a list container.
int list_unshift_sorted(LIST *list, void *ptr, int(*comparator)(const void *a, const void *b), void(*destructor)(void *ptr))
Add a pointer sorted in the list , starting by the start of the list.
LIST_NODE * list_node_pop(LIST *list)
Get a LIST_NODE pointer from the end of the list.
void * remove_list_node_f(LIST *list, LIST_NODE *node)
Internal function called each time we need to get a node out of a list.
LIST_NODE * list_search(LIST *list, void *ptr)
search ptr in list
int list_push_sorted(LIST *list, void *ptr, int(*comparator)(const void *a, const void *b), void(*destructor)(void *ptr))
Add a pointer sorted in the list , starting by the end of the list.
int list_empty_with_f(LIST *list, void(*free_fnct)(void *ptr))
Empty a LIST list of pointers.
LIST_NODE * list_search_with_f(LIST *list, int(*checkfunk)(void *ptr))
search ptr in list
int list_node_push(LIST *list, LIST_NODE *node)
Add a filled node to the end of the list.
Structure of a generic LIST container.
Structure of a generic list node.
#define n_log(__LEVEL__,...)
Logging function wrapper to get line and func.
#define LOG_ERR
error conditions
Common headers and low-level functions & define.
List structures and definitions.