]> Git Repo - uclibc-ng.git/blame - include/search.h
tmp
[uclibc-ng.git] / include / search.h
CommitLineData
e83a36ce
EA
1/* Declarations for System V style searching functions.
2 Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
64bc6412 4
e83a36ce
EA
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
64bc6412 9
e83a36ce
EA
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 Lesser General Public License for more details.
64bc6412 14
e83a36ce 15 You should have received a copy of the GNU Lesser General Public
266bdc1f
MF
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
64bc6412
EA
18
19#ifndef _SEARCH_H
e83a36ce 20#define _SEARCH_H 1
64bc6412
EA
21
22#include <features.h>
23
24#define __need_size_t
64bc6412
EA
25#include <stddef.h>
26
27__BEGIN_DECLS
28
e83a36ce
EA
29#if defined __USE_SVID || defined __USE_XOPEN_EXTENDED
30/* Prototype structure for a linked-list data structure.
31 This is the type used by the `insque' and `remque' functions. */
32
33# ifdef __USE_GNU
34struct qelem
35 {
36 struct qelem *q_forw;
37 struct qelem *q_back;
38 char q_data[1];
39 };
40# endif
41
42
43/* Insert ELEM into a doubly-linked list, after PREV. */
44extern void insque (void *__elem, void *__prev) __THROW;
45
46/* Unlink ELEM from the doubly-linked list that it is in. */
47extern void remque (void *__elem) __THROW;
cc07f235 48#endif
64bc6412 49
64bc6412 50
e83a36ce
EA
51/* For use with hsearch(3). */
52#ifndef __COMPAR_FN_T
53# define __COMPAR_FN_T
290e19f8 54typedef int (*__compar_fn_t) (const void *, const void *);
e83a36ce
EA
55
56# ifdef __USE_GNU
57typedef __compar_fn_t comparison_fn_t;
58# endif
59#endif
64bc6412 60
e83a36ce
EA
61/* Action which shall be performed in the call the hsearch. */
62typedef enum
63 {
64 FIND,
65 ENTER
66 }
67ACTION;
68
69typedef struct entry
70 {
71 char *key;
72 void *data;
73 }
74ENTRY;
75
76/* Opaque type for internal use. */
77struct _ENTRY;
78
79/* Family of hash table handling functions. The functions also
80 have reentrant counterparts ending with _r. The non-reentrant
81 functions all work on a signle internal hashing table. */
82
83/* Search for entry matching ITEM.key in internal hash table. If
84 ACTION is `FIND' return found entry or signal error by returning
85 NULL. If ACTION is `ENTER' replace existing data (if any) with
86 ITEM.data. */
87extern ENTRY *hsearch (ENTRY __item, ACTION __action) __THROW;
88
89/* Create a new hashing table which will at most contain NEL elements. */
90extern int hcreate (size_t __nel) __THROW;
91
92/* Destroy current internal hashing table. */
93extern void hdestroy (void) __THROW;
94
95#ifdef __USE_GNU
96/* Data type for reentrant functions. */
97struct hsearch_data
98 {
99 struct _ENTRY *table;
100 unsigned int size;
101 unsigned int filled;
102 };
103
104/* Reentrant versions which can handle multiple hashing tables at the
105 same time. */
106extern int hsearch_r (ENTRY __item, ACTION __action, ENTRY **__retval,
107 struct hsearch_data *__htab) __THROW;
cb97aade 108libc_hidden_proto(hsearch_r)
e83a36ce 109extern int hcreate_r (size_t __nel, struct hsearch_data *__htab) __THROW;
cb97aade 110libc_hidden_proto(hcreate_r)
e83a36ce 111extern void hdestroy_r (struct hsearch_data *__htab) __THROW;
cb97aade 112libc_hidden_proto(hdestroy_r)
e83a36ce 113#endif
64bc6412
EA
114
115
116/* The tsearch routines are very interesting. They make many
e83a36ce
EA
117 assumptions about the compiler. It assumes that the first field
118 in node must be the "key" field, which points to the datum.
119 Everything depends on that. */
64bc6412 120/* For tsearch */
e83a36ce
EA
121typedef enum
122{
123 preorder,
124 postorder,
125 endorder,
126 leaf
127}
128VISIT;
129
130/* Search for an entry matching the given KEY in the tree pointed to
131 by *ROOTP and insert a new element if not found. */
290e19f8 132extern void *tsearch (const void *__key, void **__rootp,
e83a36ce 133 __compar_fn_t __compar);
cb97aade 134libc_hidden_proto(tsearch)
e83a36ce
EA
135
136/* Search for an entry matching the given KEY in the tree pointed to
137 by *ROOTP. If no matching entry is available return NULL. */
290e19f8 138extern void *tfind (const void *__key, void *const *__rootp,
e83a36ce 139 __compar_fn_t __compar);
cb97aade 140libc_hidden_proto(tfind)
e83a36ce
EA
141
142/* Remove the element matching KEY from the tree pointed to by *ROOTP. */
290e19f8 143extern void *tdelete (const void *__restrict __key,
e83a36ce
EA
144 void **__restrict __rootp,
145 __compar_fn_t __compar);
64bc6412 146
e83a36ce
EA
147#ifndef __ACTION_FN_T
148# define __ACTION_FN_T
290e19f8 149typedef void (*__action_fn_t) (const void *__nodep, VISIT __value,
e83a36ce
EA
150 int __level);
151#endif
64bc6412 152
e83a36ce
EA
153/* Walk through the whole tree and call the ACTION callback for every node
154 or leaf. */
290e19f8 155extern void twalk (const void *__root, __action_fn_t __action);
64bc6412 156
e83a36ce
EA
157#ifdef __USE_GNU
158/* Callback type for function to free a tree node. If the keys are atomic
159 data this function should do nothing. */
160typedef void (*__free_fn_t) (void *__nodep);
64bc6412 161
e83a36ce
EA
162/* Destroy the whole tree, call FREEFCT for each node or leaf. */
163extern void tdestroy (void *__root, __free_fn_t __freefct);
cb97aade 164libc_hidden_proto(tdestroy)
64bc6412
EA
165#endif
166
64bc6412 167
e83a36ce
EA
168/* Perform linear search for KEY by comparing by COMPAR in an array
169 [BASE,BASE+NMEMB*SIZE). */
290e19f8 170extern void *lfind (const void *__key, const void *__base,
e83a36ce 171 size_t *__nmemb, size_t __size, __compar_fn_t __compar);
cb97aade 172libc_hidden_proto(lfind)
64bc6412 173
e83a36ce
EA
174/* Perform linear search for KEY by comparing by COMPAR function in
175 array [BASE,BASE+NMEMB*SIZE) and insert entry if not found. */
290e19f8 176extern void *lsearch (const void *__key, void *__base,
e83a36ce 177 size_t *__nmemb, size_t __size, __compar_fn_t __compar);
64bc6412
EA
178
179__END_DECLS
180
181#endif /* search.h */
This page took 0.247419 seconds and 4 git commands to generate.