1 /*
2 Copyright (c) 1990, 1993
3 The Regents of the University of California.  All rights reserved.
4 
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
8 1. Redistributions of source code must retain the above copyright
9 notice, this list of conditions and the following disclaimer.
10 2. Redistributions in binary form must reproduce the above copyright
11 notice, this list of conditions and the following disclaimer in the
12 documentation and/or other materials provided with the distribution.
13 3. Neither the name of the University nor the names of its contributors
14 may be used to endorse or promote products derived from this software
15 without specific prior written permission.
16 
17 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 SUCH DAMAGE.
28  */
29 /*	$NetBSD: search.h,v 1.12 1999/02/22 10:34:28 christos Exp $	*/
30 /* $FreeBSD: src/include/search.h,v 1.4 2002/03/23 17:24:53 imp Exp $ */
31 
32 /*
33  * Written by J.T. Conklin <jtc@netbsd.org>
34  * Public domain.
35  */
36 
37 #ifndef _SEARCH_H_
38 #define _SEARCH_H_
39 
40 #include <sys/cdefs.h>
41 #include <machine/ansi.h>
42 #include <sys/types.h>
43 
44 typedef struct entry {
45 	char *key;
46 	void *data;
47 } ENTRY;
48 
49 typedef enum {
50 	FIND, ENTER
51 } ACTION;
52 
53 typedef enum {
54 	preorder,
55 	postorder,
56 	endorder,
57 	leaf
58 } VISIT;
59 
60 #ifdef _SEARCH_PRIVATE
61 typedef struct node {
62 	char         *key;
63 	struct node  *llink, *rlink;
64 } node_t;
65 #endif
66 
67 struct hsearch_data
68 {
69   struct internal_head *htable;
70   size_t htablesize;
71 };
72 
73 #ifndef __compar_fn_t_defined
74 #define __compar_fn_t_defined
75 typedef int (*__compar_fn_t) (const void *, const void *);
76 #endif
77 
78 __BEGIN_DECLS
79 int	 hcreate(size_t);
80 void	 hdestroy(void);
81 ENTRY	*hsearch(ENTRY, ACTION);
82 int	 hcreate_r(size_t, struct hsearch_data *);
83 void	 hdestroy_r(struct hsearch_data *);
84 int	hsearch_r(ENTRY, ACTION, ENTRY **, struct hsearch_data *);
85 void	*tdelete(const void *__restrict, void **__restrict, __compar_fn_t);
86 void	tdestroy (void *, void (*)(void *));
87 void	*tfind(const void *, void **, __compar_fn_t);
88 void	*tsearch(const void *, void **, __compar_fn_t);
89 void      twalk(const void *, void (*)(const void *, VISIT, int));
90 __END_DECLS
91 
92 #endif /* !_SEARCH_H_ */
93