search.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. /* Get __compar_fn_t from stdlib.h */
  26. #include <stdlib.h>
  27. __BEGIN_DECLS
  28. #if 0
  29. #ifndef __COMPAR_FN_T
  30. #define __COMPAR_FN_T
  31. typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t));
  32. #endif
  33. #endif
  34. /* for use with hsearch(3) */
  35. typedef struct entry { char *key; char *data; } ENTRY;
  36. typedef enum { FIND, ENTER } ACTION;
  37. extern ENTRY * hsearch __P((ENTRY __item, ACTION __action));
  38. extern int hcreate __P((unsigned __nel));
  39. extern void hdestroy __P((void));
  40. /* The tsearch routines are very interesting. They make many
  41. * assumptions about the compiler. It assumpts that the first field
  42. * in node must be the "key" field, which points to the datum.
  43. * Everything depends on that. It is a very tricky stuff. H.J.
  44. */
  45. /* For tsearch */
  46. typedef enum { preorder, postorder, endorder, leaf } VISIT;
  47. extern void *tsearch __P((__const void * __key, void **__rootp,
  48. __compar_fn_t compar));
  49. extern void *tfind __P((__const void * __key, void * __const * __rootp,
  50. __compar_fn_t compar));
  51. extern void *tdelete __P((__const void * __key, void ** __rootp,
  52. __compar_fn_t compar));
  53. #ifndef __ACTION_FN_T
  54. #define __ACTION_FN_T
  55. /* FYI, the first argument should be a pointer to "key".
  56. * Please read the man page for details.
  57. */
  58. typedef void (*__action_fn_t) __P((__const void *__nodep,
  59. __const VISIT __value,
  60. __const int __level));
  61. #endif
  62. extern void twalk __P((__const void * __root, __action_fn_t action));
  63. extern void * lfind __P((__const void * __key, __const void * __base,
  64. size_t * __nmemb, size_t __size,
  65. __compar_fn_t __compar));
  66. extern void * lsearch __P((__const void * __key, __const void * __base,
  67. size_t * __nmemb, size_t __size,
  68. __compar_fn_t __compar));
  69. __END_DECLS
  70. #endif /* search.h */