search.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /* $NetBSD: search.h,v 1.12 1999/02/22 10:34:28 christos Exp $ */
  2. /* $FreeBSD: src/include/search.h,v 1.4 2002/03/23 17:24:53 imp Exp $ */
  3. /*
  4. * Written by J.T. Conklin <jtc@netbsd.org>
  5. * Public domain.
  6. */
  7. #ifndef _SEARCH_H_
  8. #define _SEARCH_H_
  9. #include <sys/cdefs.h>
  10. #include <machine/ansi.h>
  11. #include <sys/types.h>
  12. typedef struct entry {
  13. char *key;
  14. void *data;
  15. } ENTRY;
  16. typedef enum {
  17. FIND, ENTER
  18. } ACTION;
  19. typedef enum {
  20. preorder,
  21. postorder,
  22. endorder,
  23. leaf
  24. } VISIT;
  25. #ifdef _SEARCH_PRIVATE
  26. typedef struct node {
  27. char *key;
  28. struct node *llink, *rlink;
  29. } node_t;
  30. #endif
  31. struct hsearch_data
  32. {
  33. struct internal_head *htable;
  34. size_t htablesize;
  35. };
  36. #ifndef __compar_fn_t_defined
  37. #define __compar_fn_t_defined
  38. typedef int (*__compar_fn_t) (const void *, const void *);
  39. #endif
  40. __BEGIN_DECLS
  41. int hcreate(size_t);
  42. void hdestroy(void);
  43. ENTRY *hsearch(ENTRY, ACTION);
  44. int hcreate_r(size_t, struct hsearch_data *);
  45. void hdestroy_r(struct hsearch_data *);
  46. int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *);
  47. void *tdelete(const void *__restrict, void **__restrict, __compar_fn_t);
  48. void tdestroy (void *, void (*)(void *));
  49. void *tfind(const void *, void **, __compar_fn_t);
  50. void *tsearch(const void *, void **, __compar_fn_t);
  51. void twalk(const void *, void (*)(const void *, VISIT, int));
  52. __END_DECLS
  53. #endif /* !_SEARCH_H_ */