sll.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef TOOLBOX_LIST_SLL_H
  2. #define TOOLBOX_LIST_SLL_H
  3. #include "toolbox/errcode.h"
  4. #include "toolbox/errno.h"
  5. #include "toolbox/vptr.h"
  6. #include <stddef.h>
  7. struct sll_item {
  8. void *item;
  9. const size_t size;
  10. struct sll_item *next;
  11. };
  12. struct sll {
  13. size_t size;
  14. struct sll_item *head;
  15. };
  16. __attribute__((__pure__))
  17. struct sll *
  18. sll_create(void);
  19. RET_TYPE
  20. sll_destroy(struct sll **self);
  21. RET_TYPE
  22. sll_insert(struct sll *restrict self
  23. , const void *restrict item, const size_t item_size
  24. , const size_t index);
  25. RET_TYPE
  26. sll_append(struct sll *restrict self
  27. , const void *restrict item, const size_t item_size);
  28. struct vptr
  29. sll_remove(struct sll *self, const size_t index);
  30. struct vptr
  31. sll_get(struct sll *self, const size_t index);
  32. RET_TYPE
  33. sll_for_each(struct sll *self, RET_TYPE (*for_each)(void *, size_t));
  34. #define sll_size(self) \
  35. (self->size)
  36. #define sll_pop(self) \
  37. sll_remove(self, ssl_size(self))
  38. #define sll_prepend(self, item, item_size) \
  39. sll_insert(self, item, item_size, 0)
  40. #endif