sllist.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef SL_LIST_H__
  2. # define SL_LIST_H__
  3. struct sl_list_item {
  4. void *data;
  5. struct sl_list_item *next;
  6. };
  7. typedef struct {
  8. unsigned int count;
  9. struct sl_list_item *first;
  10. } sl_list;
  11. /**
  12. * Allocate a new list and return it
  13. * result should be unallocated with sllist_destroy()
  14. **/
  15. sl_list *sllist_create();
  16. /**
  17. * Free all ressources allocated by sllist_create
  18. **/
  19. void sllist_destroy(sl_list *list);
  20. /**
  21. * Get the numbers of items contained in sl_list
  22. **/
  23. unsigned int sllist_count(const sl_list * const list);
  24. /**
  25. * Add an item at the end of the list
  26. * TODO
  27. **/
  28. sl_list *sllist_pushback(sl_list *list, void *item);
  29. /**
  30. * Add an item at the begining of the list
  31. * TODO
  32. **/
  33. sl_list *sllist_pushfront(sl_list *list, void *item);
  34. /**
  35. * Remove the last item of the list and return it
  36. * TODO
  37. **/
  38. void *sllist_popback(sl_list *list, void *item);
  39. /**
  40. * Remove the first item of the list and return it
  41. * TODO
  42. **/
  43. void *sllist_popfront(sl_list *list, void *item);
  44. /**
  45. * Get the item at position %pos
  46. * TODO
  47. **/
  48. void *sllist_at(sl_list *list, unsigned int pos);
  49. /**
  50. * Remove the item at position %pos, and return it
  51. * TODO
  52. **/
  53. void *sllist_removeat(sl_list *list, unsigned int pos);
  54. /**
  55. * Remove all elements
  56. **/
  57. sl_list *sllist_clear(sl_list *list);
  58. #endif /* SL_LIST_H__ */