summaryrefslogtreecommitdiff
path: root/include/search.h
blob: fa3e5c083c896b8c2d15f3a25c0162bc230086a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/* Copyright (C) 1993 Ulrich Drepper

This file is intended to be included in the GNU C Library and the
Linux C Library. So the copyright notice will be:


Copyright (C) 1993 Free Software Foundation, Inc.
This file is part of the GNU C Library.

The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.

The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB.  If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA.


For now the file can be distributed under the LGPL.  */

#ifndef _SEARCH_H
#define _SEARCH_H

#include <features.h>

#define __need_size_t
#define __need_NULL
#include <stddef.h>

/* Get __compar_fn_t from stdlib.h */
#include <stdlib.h>

__BEGIN_DECLS

#if 0
#ifndef __COMPAR_FN_T
#define __COMPAR_FN_T
typedef int (*__compar_fn_t) __P ((__const __ptr_t, __const __ptr_t));
#endif
#endif

/* for use with hsearch(3) */

typedef struct entry { char *key; char *data; } ENTRY;
typedef enum { FIND, ENTER } ACTION;

extern ENTRY * hsearch __P((ENTRY __item, ACTION __action));
extern int     hcreate __P((unsigned __nel));
extern void    hdestroy __P((void));


/* The tsearch routines are very interesting. They make many
 * assumptions about the compiler. It assumpts that the first field
 * in node must be the "key" field, which points to the datum.
 * Everything depends on that. It is a very tricky stuff. H.J.
 */
/* For tsearch */
typedef enum { preorder, postorder, endorder, leaf } VISIT;

extern void *tsearch __P((__const void * __key, void **__rootp,
		__compar_fn_t compar));

extern void *tfind __P((__const void * __key, void * __const * __rootp,
		__compar_fn_t compar));

extern void *tdelete __P((__const void * __key, void ** __rootp,
		__compar_fn_t compar));

#ifndef __ACTION_FN_T
#define __ACTION_FN_T
/* FYI, the first argument should be a pointer to "key".
 * Please read the man page for details.
 */
typedef void (*__action_fn_t) __P((__const void *__nodep,
				   __const VISIT __value,
				   __const int __level));
#endif

extern void twalk __P((__const void * __root, __action_fn_t action));


extern void * lfind __P((__const void * __key, __const void * __base,
                         size_t * __nmemb, size_t __size,
                         __compar_fn_t __compar));

extern void * lsearch __P((__const void * __key, __const void * __base,
                         size_t * __nmemb, size_t __size,
                         __compar_fn_t __compar));

__END_DECLS

#endif /* search.h */