search.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #ifndef _SEARCH_H
  2. #define _SEARCH_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #if __STDC_VERSION__ >= 199901L
  7. #define __restrict restrict
  8. #elif !defined(__GNUC__)
  9. #define __restrict
  10. #endif
  11. #define __NEED_size_t
  12. #include <bits/alltypes.h>
  13. typedef enum { FIND, ENTER } ACTION;
  14. typedef enum { preorder, postorder, endorder, leaf } VISIT;
  15. typedef struct {
  16. char *key;
  17. void *data;
  18. } ENTRY;
  19. int hcreate(size_t);
  20. void hdestroy(void);
  21. ENTRY *hsearch(ENTRY, ACTION);
  22. void insque(void *, void *);
  23. void remque(void *);
  24. void *lsearch(const void *, void *, size_t *, size_t,
  25. int (*)(const void *, const void *));
  26. void *lfind(const void *, const void *, size_t *, size_t,
  27. int (*)(const void *, const void *));
  28. void *tdelete(const void *__restrict, void **__restrict, int(*)(const void *, const void *));
  29. void *tfind(const void *, void *const *, int(*)(const void *, const void *));
  30. void *tsearch(const void *, void **, int (*)(const void *, const void *));
  31. void twalk(const void *, void (*)(const void *, VISIT, int));
  32. #ifdef _GNU_SOURCE
  33. struct qelem {
  34. struct qelem *q_forw, *q_back;
  35. char q_data[1];
  36. };
  37. void tdestroy(void *, void (*)(void *));
  38. #endif
  39. #ifdef __cplusplus
  40. }
  41. #endif
  42. #endif