| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- #ifndef SL_LIST_H__
- # define SL_LIST_H__
- # define SL_LIST_BUFLEN 8
- struct sl_list_item {
- void *data[SL_LIST_BUFLEN];
- struct sl_list_item *next;
- };
- typedef struct {
- unsigned int count;
- struct sl_list_item *first;
- } sl_list;
- /**
- * Allocate a new list and return it
- * result should be unallocated with sllist_destroy()
- **/
- sl_list *sllist_create();
- /**
- * Free all ressources allocated by sllist_create
- **/
- void sllist_destroy(sl_list *list);
- /**
- * Get the numbers of items contained in sl_list
- **/
- unsigned int sllist_count(const sl_list * const list);
- /**
- * Add an item at the end of the list
- **/
- sl_list *sllist_pushback(sl_list *list, void *item);
- /**
- * Remove the last item of the list and return it
- **/
- void *sllist_popback(sl_list *list);
- /**
- * Get the item at position %pos
- **/
- void *sllist_at(const sl_list * const list, unsigned int pos);
- /**
- * Remove the item at position %pos, and return it
- * TODO
- **/
- void *sllist_removeat(sl_list *list, unsigned int pos);
- /**
- * Remove all elements
- **/
- sl_list *sllist_clear(sl_list *list);
- /**
- * Return index of first item, using compare fnc
- * Return -1 on failure
- * TODO
- **/
- int sllist_find(sl_list *list, int(*fnc)(const void *cmp, const void *param), const void *param);
- /**
- * Execute function foreach values of list
- * Param 2 is custom_data
- * A -1 return value will act as a `break` instruction
- * return the number of iterated objects
- **/
- int sllist_foreach(sl_list *list, int(*fnc)(void **item, void *custom), void *custom);
- /**
- * Find and remove item(s)
- * return nb of items successfully removed
- **/
- int sllist_remove(sl_list *list, int(*fnc)(const void *a, const void *b), void *item);
- /**
- * Find and remove item(s), maximum n items will be removed
- * return nb of items successfully removed
- **/
- int sllist_n_remove(sl_list *list, int(*fnc)(const void *a, const void *b), void *item, unsigned int n);
- /**
- * Comp functions
- * usable with sllist_find
- **/
- int sllist_cmp_int(const void *a, const void *b);
- int sllist_cmp_string(const void *a, const void *b);
- #endif /* SL_LIST_H__ */
|