sllist.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef SL_LIST_H__
  2. # define SL_LIST_H__
  3. # define SL_LIST_BUFLEN 8
  4. struct sl_list_item {
  5. void *data[SL_LIST_BUFLEN];
  6. struct sl_list_item *next;
  7. };
  8. typedef struct {
  9. unsigned int count;
  10. struct sl_list_item *first;
  11. } sl_list;
  12. /**
  13. * Allocate a new list and return it
  14. * result should be unallocated with sllist_destroy()
  15. **/
  16. sl_list *sllist_create();
  17. /**
  18. * Free all ressources allocated by sllist_create
  19. **/
  20. void sllist_destroy(sl_list *list);
  21. /**
  22. * Get the numbers of items contained in sl_list
  23. **/
  24. unsigned int sllist_count(const sl_list * const list);
  25. /**
  26. * Add an item at the end of the list
  27. **/
  28. sl_list *sllist_pushback(sl_list *list, void *item);
  29. /**
  30. * Remove the last item of the list and return it
  31. **/
  32. void *sllist_popback(sl_list *list);
  33. /**
  34. * Get the item at position %pos
  35. **/
  36. void *sllist_at(const sl_list * const list, unsigned int pos);
  37. /**
  38. * Remove the item at position %pos, and return it
  39. * TODO
  40. **/
  41. void *sllist_removeat(sl_list *list, unsigned int pos);
  42. /**
  43. * Remove all elements
  44. **/
  45. sl_list *sllist_clear(sl_list *list);
  46. /**
  47. * Return index of first item, using compare fnc
  48. * Return -1 on failure
  49. * TODO
  50. **/
  51. int sllist_find(sl_list *list, int(*fnc)(const void *cmp, const void *param), const void *param);
  52. /**
  53. * Execute function foreach values of list
  54. * Param 2 is custom_data
  55. * A -1 return value will act as a `break` instruction
  56. * return the number of iterated objects
  57. **/
  58. int sllist_foreach(sl_list *list, int(*fnc)(void **item, void *custom), void *custom);
  59. #endif /* SL_LIST_H__ */