list.h 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #ifndef LIST_H
  2. #define LIST_H
  3. /*
  4. * Missing functions:
  5. * - version of listforeach() which allows passing arguments and
  6. * which will return an argument
  7. */
  8. #ifndef LIST
  9. typedef struct List
  10. {
  11. struct List *next;
  12. } LIST;
  13. #endif
  14. #ifndef LISTFUNC_DEFINED
  15. #define LISTFUNC_DEFINED
  16. typedef int (*cmpfunc) (const void *sample, const void *each);
  17. typedef void (*freefunc) (const void *elt);
  18. typedef void (*cpyfunc) (const void *dst, const void *src);
  19. typedef void (*actfunc) (const void *elt);
  20. #endif
  21. extern LIST *listitem(size_t size);
  22. extern LIST *listadd(LIST * head, LIST * elt, cmpfunc cmp);
  23. extern LIST *listaddnth(LIST * head, LIST * elt, int nth);
  24. extern LIST *listprep(LIST * head, LIST * elt);
  25. extern LIST *listapp(LIST * head, LIST * elt);
  26. extern LIST *listunlink(LIST * head, LIST * elt);
  27. extern LIST *listunlinknth(LIST * head, int nth);
  28. extern LIST *listdel(LIST * head, LIST * elt, freefunc func);
  29. extern LIST *listdelnth(LIST * head, int nth, freefunc func);
  30. extern int listcnt(LIST * head);
  31. extern LIST *listdup(LIST * head, cpyfunc cpy, size_t size);
  32. extern LIST *listsplit(LIST * head, LIST * elt);
  33. extern LIST *listsplitnth(LIST * head, int nth);
  34. extern LIST *listjoin(LIST * head, LIST * tail);
  35. extern LIST *listsort(LIST * head, cmpfunc cmp);
  36. extern LIST *listrev(LIST * head);
  37. extern LIST *listshuffle(LIST * head);
  38. extern LIST *listdelall(LIST * head, freefunc func);
  39. extern LIST **list2array(LIST * head);
  40. extern LIST *array2list(LIST ** array);
  41. extern void listforeach(LIST * head, actfunc action);
  42. extern int listidx(LIST * head, LIST * elt);
  43. extern LIST *listlast(LIST * head);
  44. extern LIST *listnth(LIST * head, int nth);
  45. extern LIST *listfind(LIST * head, LIST * elt, cmpfunc cmp);
  46. extern LIST *listfinddatum(LIST * head, void *datum, cmpfunc cmp);
  47. extern LIST *listbsearch(LIST * head, LIST * elt, cmpfunc cmp);
  48. extern LIST *listbsearchdatum(LIST * head, const void *data, cmpfunc cmp);
  49. #endif