search.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. /* Copyright (C) 1993 Ulrich Drepper
  2. This file is intended to be included in the GNU C Library and the
  3. Linux C Library. So the copyright notice will be:
  4. Copyright (C) 1993 Free Software Foundation, Inc.
  5. This file is part of the GNU C Library.
  6. The GNU C Library is free software; you can redistribute it and/or
  7. modify it under the terms of the GNU Library General Public License as
  8. published by the Free Software Foundation; either version 2 of the
  9. License, or (at your option) any later version.
  10. The GNU C Library is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. Library General Public License for more details.
  14. You should have received a copy of the GNU Library General Public
  15. License along with the GNU C Library; see the file COPYING.LIB. If
  16. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  17. Cambridge, MA 02139, USA.
  18. For now the file can be distributed under the LGPL. */
  19. #ifndef _SEARCH_H
  20. #define _SEARCH_H
  21. #include <features.h>
  22. #define __need_size_t
  23. #define __need_NULL
  24. #include <stddef.h>
  25. __BEGIN_DECLS
  26. #ifndef __COMPAR_FN_T
  27. #define __COMPAR_FN_T
  28. typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t));
  29. #endif
  30. /* for use with hsearch(3) */
  31. typedef struct entry { char *key; char *data; } ENTRY;
  32. typedef enum { FIND, ENTER } ACTION;
  33. extern ENTRY * hsearch __P((ENTRY __item, ACTION __action));
  34. extern int hcreate __P((unsigned __nel));
  35. extern void hdestroy __P((void));
  36. /* The tsearch routines are very interesting. They make many
  37. * assumptions about the compiler. It assumpts that the first field
  38. * in node must be the "key" field, which points to the datum.
  39. * Everything depends on that. It is a very tricky stuff. H.J.
  40. */
  41. /* For tsearch */
  42. typedef enum { preorder, postorder, endorder, leaf } VISIT;
  43. extern void *tsearch __P((__const void * __key, void **__rootp,
  44. __compar_fn_t compar));
  45. extern void *tfind __P((__const void * __key, __const void ** __rootp,
  46. __compar_fn_t compar));
  47. extern void *tdelete __P((__const void * __key, void ** __rootp,
  48. __compar_fn_t compar));
  49. #ifndef __ACTION_FN_T
  50. #define __ACTION_FN_T
  51. /* FYI, the first argument should be a pointer to "key".
  52. * Please read the man page for details.
  53. */
  54. typedef void (*__action_fn_t) __P((__const void *__nodep,
  55. __const VISIT __value,
  56. __const int __level));
  57. #endif
  58. extern void twalk __P((__const void * __root, __action_fn_t action));
  59. extern void * lfind __P((__const void * __key, __const void * __base,
  60. size_t * __nmemb, size_t __size,
  61. __compar_fn_t __compar));
  62. extern void * lsearch __P((__const void * __key, __const void * __base,
  63. size_t * __nmemb, size_t __size,
  64. __compar_fn_t __compar));
  65. __END_DECLS
  66. #endif /* search.h */