28 list -> nb_max_items = 0 ;
30 list -> nb_max_items = max_items ;
32 list -> nb_items = 0 ;
33 list -> start = list -> end = NULL ;
54 node -> destroy_func = destructor ;
55 node -> next = node -> prev = NULL ;
78 if( node -> prev && node -> next )
80 node -> prev -> next = node -> next ;
81 node -> next -> prev = node -> prev ;
85 if( node -> prev == NULL && node -> next )
87 node -> next -> prev = NULL ;
88 list -> start = node -> next ;
92 if( node -> prev && node -> next == NULL )
94 node -> prev -> next = NULL ;
95 list -> end = node -> prev ;
99 if( node -> prev == NULL && node -> next == NULL )
102 list -> start = list -> end = NULL ;
108 list -> nb_items -- ;
124 if( list -> nb_max_items > 0 && ( list -> nb_items >= list -> nb_max_items ) )
131 list -> end -> next = node ;
132 node -> prev = list -> end ;
137 list -> start = list -> end = node ;
139 list -> nb_items ++ ;
154 if( list -> nb_items == 0 || list -> end == NULL )
159 nodeptr = list -> end ;
160 if( list -> end -> prev )
162 list -> end = list -> end -> prev ;
163 list -> end -> next = NULL ;
165 list -> nb_items -- ;
166 if( list -> nb_items == 0 )
167 list -> start = list -> end = NULL ;
183 if( list -> nb_items == 0 || list -> start == NULL )
187 nodeptr = list -> start ;
189 if( list -> start -> next )
191 list -> start = list -> start -> next ;
192 list -> start -> prev = NULL ;
195 list -> nb_items -- ;
197 if( list -> nb_items == 0 )
198 list -> start = list -> end = NULL ;
216 if( list -> nb_max_items > 0 && ( list -> nb_items >= list -> nb_max_items ) )
224 list -> start = node ;
228 list -> start = list -> end = node ;
230 list -> nb_items ++ ;
251 if( list -> nb_max_items > 0 && ( list -> nb_items >= list -> nb_max_items ) )
260 list -> nb_items ++ ;
264 list -> end -> next = node ;
265 node -> prev = list -> end ;
270 list -> start = list -> end = node ;
285int list_push_sorted(
LIST *list,
void *ptr,
int (*comparator)(
const void *a,
const void *b ),
void (*destructor)(
void *ptr ) )
292 if( list -> nb_max_items > 0 && ( list -> nb_items >= list -> nb_max_items ) )
300 nodeptr = list -> end ;
301 while( nodeptr && ( comparator( ptr, nodeptr -> ptr ) < 0 ) )
302 nodeptr = nodeptr -> prev ;
321 list -> end = newnode ;
324 list -> nb_items ++ ;
349 if( list -> nb_max_items > 0 && ( list -> nb_items >= list -> nb_max_items ) )
357 list -> nb_items ++ ;
362 list -> start = node ;
366 list -> start = list -> end = node ;
382int list_unshift_sorted(
LIST *list,
void *ptr,
int (*comparator)(
const void *a,
const void *b ),
void (*destructor)(
void *ptr ) )
389 if( list -> nb_max_items > 0 && ( list -> nb_items >= list -> nb_max_items ) )
397 nodeptr = list -> start ;
398 while( nodeptr && ( comparator( ptr, nodeptr -> ptr ) > 0 ) )
399 nodeptr = nodeptr -> next ;
418 list -> start = newnode ;
421 list -> nb_items ++ ;
444 if( list -> nb_items == 0 || list -> end == NULL )
447 nodeptr = list -> end ;
448 ptr = nodeptr -> ptr ;
450 if( list -> end -> prev )
452 list -> end = list -> end -> prev ;
453 list -> end -> next = NULL ;
456 list -> nb_items -- ;
457 if( list -> nb_items == 0 )
458 list -> start = list -> end = NULL ;
479 if( list -> nb_items == 0 || list -> start == NULL )
482 nodeptr = list -> start ;
483 ptr = nodeptr -> ptr ;
485 if( list -> start -> next )
487 list -> start = list -> start -> next ;
488 list -> start -> prev = NULL ;
491 list -> nb_items -- ;
493 if( list -> nb_items == 0 )
494 list -> start = list -> end = NULL ;
514 if( node -> ptr == ptr )
534 if( checkfunk( node -> ptr ) )
549 LIST_NODE *node = NULL, *node_ptr = NULL ;
553 node = list -> start ;
557 node = node -> next ;
558 if( node_ptr -> destroy_func != NULL )
560 node_ptr -> destroy_func( node_ptr -> ptr );
564 list -> start = list -> end = NULL ;
565 list -> nb_items = 0 ;
579 LIST_NODE *node = NULL, *node_ptr = NULL ;
583 node = list -> start ;
587 node = node -> next ;
588 free_fnct( node_ptr -> ptr );
591 list -> start = list -> end = NULL ;
592 list -> nb_items = 0 ;
#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
LIST_NODE * start
pointer to the start of the list
void * list_pop_f(LIST *list)
Get a pointer from the end 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.
void * list_shift_f(LIST *list)
Get a pointer from the start of the list.
LIST * new_generic_list(int max_items)
Initialiaze a generic list container to max_items pointers.
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 hugly functions & define.
List structures and definitions.