1 /* Declarations for System V style searching functions.
2 Copyright (C) 1995, 1996, 1997 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
31 #if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
32 /* Prototype structure for a linked-list data structure.
33 This is the type used by the `insque' and `remque' functions. */
43 /* Insert ELEM into a doubly-linked list, after PREV. */
44 extern void insque __P ((void *__elem, void *__prev));
46 /* Unlink ELEM from the doubly-linked list that it is in. */
47 extern void remque __P ((void *__elem));
51 /* For use with hsearch(3). */
53 # define __COMPAR_FN_T
54 typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t));
57 /* Action which shall be performed in the call the hsearch. */
72 /* Opaque type for internal use. */
75 /* Family of hash table handling functions. The functions also
76 have reentrant counterparts ending with _r. The non-reentrant
77 functions all work on a signle internal hashing table. */
79 /* Search for entry matching ITEM.key in internal hash table. If
80 ACTION is `FIND' return found entry or signal error by returning
81 NULL. If ACTION is `ENTER' replace existing data (if any) with
83 extern ENTRY *hsearch __P ((ENTRY __item, ACTION __action));
85 /* Create a new hashing table which will at most contain NEL elements. */
86 extern int hcreate __P ((size_t __nel));
88 /* Destroy current internal hashing table. */
89 extern void hdestroy __P ((void));
92 /* Data type for reentrant functions. */
100 /* Reentrant versions which can handle multiple hashing tables at the
102 extern int hsearch_r __P ((ENTRY __item, ACTION __action, ENTRY **__retval,
103 struct hsearch_data *__htab));
104 extern int hcreate_r __P ((size_t __nel, struct hsearch_data *htab));
105 extern void hdestroy_r __P ((struct hsearch_data *htab));
109 /* The tsearch routines are very interesting. They make many
110 assumptions about the compiler. It assumes that the first field
111 in node must be the "key" field, which points to the datum.
112 Everything depends on that. */
123 /* Search for an entry matching the given KEY in the tree pointed to
124 by *ROOTP and insert a new element if not found. */
125 extern void *tsearch __P ((__const void *__key, void **__rootp,
126 __compar_fn_t compar));
127 extern void *__tsearch __P ((__const void *__key, void **__rootp,
128 __compar_fn_t compar));
130 /* Search for an entry matching the given KEY in the tree pointed to
131 by *ROOTP. If no matching entry is available return NULL. */
132 extern void *tfind __P ((__const void *__key, void *__const *__rootp,
133 __compar_fn_t compar));
134 extern void *__tfind __P ((__const void *__key, void *__const *__rootp,
135 __compar_fn_t compar));
137 /* Remove the element matching KEY from the tree pointed to by *ROOTP. */
138 extern void *tdelete __P ((__const void *__key, void **__rootp,
139 __compar_fn_t compar));
140 extern void *__tdelete __P ((__const void *__key, void **__rootp,
141 __compar_fn_t compar));
143 #ifndef __ACTION_FN_T
144 # define __ACTION_FN_T
145 typedef void (*__action_fn_t) __P ((__const void *__nodep,
150 /* Walk through the whole tree and call the ACTION callback for every node
152 extern void twalk __P ((__const void *__root, __action_fn_t action));
154 extern void __twalk __P ((__const void *__root, __action_fn_t action));
157 /* Callback type for function to free a tree node. If the keys are atomic
158 data this function should do nothing. */
159 typedef void (*__free_fn_t) __P ((void *__nodep));
161 /* Destroy the whole tree, call FREEFCT for each node or leaf. */
162 extern void __tdestroy __P ((void *__root, __free_fn_t freefct));
163 extern void tdestroy __P ((void *__root, __free_fn_t freefct));
167 /* Perform linear search for KEY by comparing by COMPAR in an array
168 [BASE,BASE+NMEMB*SIZE). */
169 extern void *lfind __P ((__const void *__key, __const void *__base,
170 size_t *__nmemb, size_t __size,
171 __compar_fn_t __compar));
173 /* Perform linear search for KEY by comparing by COMPAR function in
174 array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */
175 extern void *lsearch __P ((__const void *__key, void *__base, size_t *__nmemb,
176 size_t __size, __compar_fn_t __compar));
180 #endif /* search.h */