search.h revision 1.19 1 1.19 christos /* $NetBSD: search.h,v 1.19 2011/09/14 23:34:26 christos Exp $ */
2 1.6 cgd
3 1.1 jtc /*
4 1.15 salo * Written by J.T. Conklin <jtc (at) NetBSD.org>
5 1.7 jtc * Public domain.
6 1.1 jtc */
7 1.1 jtc
8 1.1 jtc #ifndef _SEARCH_H_
9 1.1 jtc #define _SEARCH_H_
10 1.11 kleink
11 1.2 jtc #include <sys/cdefs.h>
12 1.2 jtc #include <machine/ansi.h>
13 1.1 jtc
14 1.5 cgd #ifdef _BSD_SIZE_T_
15 1.5 cgd typedef _BSD_SIZE_T_ size_t;
16 1.5 cgd #undef _BSD_SIZE_T_
17 1.2 jtc #endif
18 1.1 jtc
19 1.9 jtc typedef struct entry {
20 1.9 jtc char *key;
21 1.11 kleink void *data;
22 1.9 jtc } ENTRY;
23 1.9 jtc
24 1.19 christos #ifdef _NETBSD_SOURCE
25 1.19 christos struct _ENTRY;
26 1.19 christos struct hsearch_data {
27 1.19 christos struct _ENTRY *table;
28 1.19 christos size_t size;
29 1.19 christos size_t filled;
30 1.19 christos };
31 1.19 christos #endif
32 1.19 christos
33 1.9 jtc typedef enum {
34 1.9 jtc FIND, ENTER
35 1.9 jtc } ACTION;
36 1.9 jtc
37 1.8 jtc typedef enum {
38 1.8 jtc preorder,
39 1.8 jtc postorder,
40 1.8 jtc endorder,
41 1.8 jtc leaf
42 1.8 jtc } VISIT;
43 1.12 christos
44 1.12 christos #ifdef _SEARCH_PRIVATE
45 1.12 christos typedef struct node {
46 1.12 christos char *key;
47 1.12 christos struct node *llink, *rlink;
48 1.12 christos } node_t;
49 1.12 christos #endif
50 1.8 jtc
51 1.1 jtc __BEGIN_DECLS
52 1.14 christos #ifndef __BSEARCH_DECLARED
53 1.14 christos #define __BSEARCH_DECLARED
54 1.14 christos /* also in stdlib.h */
55 1.16 perry void *bsearch(const void *, const void *, size_t, size_t,
56 1.16 perry int (*)(const void *, const void *));
57 1.14 christos #endif /* __BSEARCH_DECLARED */
58 1.19 christos
59 1.16 perry int hcreate(size_t);
60 1.16 perry void hdestroy(void);
61 1.16 perry ENTRY *hsearch(ENTRY, ACTION);
62 1.16 perry
63 1.19 christos #ifdef _NETBSD_SOURCE
64 1.19 christos int hcreate_r(size_t, struct hsearch_data *);
65 1.19 christos void hdestroy_r(struct hsearch_data *);
66 1.19 christos int hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *);
67 1.19 christos #endif /* _NETBSD_SOURCE */
68 1.19 christos
69 1.16 perry void *lfind(const void *, const void *, size_t *, size_t,
70 1.16 perry int (*)(const void *, const void *));
71 1.18 drochner void *lsearch(const void *, void *, size_t *, size_t,
72 1.16 perry int (*)(const void *, const void *));
73 1.16 perry void insque(void *, void *);
74 1.16 perry void remque(void *);
75 1.16 perry
76 1.17 kleink void *tdelete(const void * __restrict, void ** __restrict,
77 1.16 perry int (*)(const void *, const void *));
78 1.17 kleink void *tfind(const void *, void * const *,
79 1.16 perry int (*)(const void *, const void *));
80 1.16 perry void *tsearch(const void *, void **,
81 1.16 perry int (*)(const void *, const void *));
82 1.17 kleink void twalk(const void *, void (*)(const void *, VISIT, int));
83 1.1 jtc __END_DECLS
84 1.1 jtc
85 1.11 kleink #endif /* !_SEARCH_H_ */
86