*** empty log message ***
[coreutils.git] / lib / search_.h
blob62636227092cb862c850068b65a7c535232eb2db
1 /* For use with hsearch(3). */
2 #ifndef __COMPAR_FN_T
3 # define __COMPAR_FN_T
4 typedef int (*__compar_fn_t) (const void *, const void *);
6 # ifdef __USE_GNU
7 typedef __compar_fn_t comparison_fn_t;
8 # endif
9 #endif
11 /* The tsearch routines are very interesting. They make many
12 assumptions about the compiler. It assumes that the first field
13 in node must be the "key" field, which points to the datum.
14 Everything depends on that. */
15 /* For tsearch */
16 typedef enum
18 preorder,
19 postorder,
20 endorder,
21 leaf
23 VISIT;
25 /* Search for an entry matching the given KEY in the tree pointed to
26 by *ROOTP and insert a new element if not found. */
27 extern void *tsearch (const void *__key, void **__rootp,
28 __compar_fn_t __compar);
30 /* Search for an entry matching the given KEY in the tree pointed to
31 by *ROOTP. If no matching entry is available return NULL. */
32 extern void *tfind (const void *__key, void *const *__rootp,
33 __compar_fn_t __compar);
35 /* Remove the element matching KEY from the tree pointed to by *ROOTP. */
36 extern void *tdelete (const void *__restrict __key,
37 void **__restrict __rootp,
38 __compar_fn_t __compar);
40 #ifndef __ACTION_FN_T
41 # define __ACTION_FN_T
42 typedef void (*__action_fn_t) (const void *__nodep, VISIT __value,
43 int __level);
44 #endif
46 /* Walk through the whole tree and call the ACTION callback for every node
47 or leaf. */
48 extern void twalk (const void *__root, __action_fn_t __action);
50 #ifdef __USE_GNU
51 /* Callback type for function to free a tree node. If the keys are atomic
52 data this function should do nothing. */
53 typedef void (*__free_fn_t) (void *__nodep);
55 /* Destroy the whole tree, call FREEFCT for each node or leaf. */
56 extern void tdestroy (void *__root, __free_fn_t __freefct);
57 #endif