blob: 5930bcd5625d2d3ea99eb265057b0effac20a979 [file] [log] [blame]
Ben Cheng21eab512012-03-13 23:04:57 -07001/*-
2 * Written by J.T. Conklin <jtc@netbsd.org>
3 * Public domain.
4 *
5 * $NetBSD: search.h,v 1.12 1999/02/22 10:34:28 christos Exp $
6 * $FreeBSD: release/9.0.0/include/search.h 105250 2002-10-16 14:29:23Z robert $
7 */
8
9#ifndef _SEARCH_H_
10#define _SEARCH_H_
11
12#include <sys/cdefs.h>
Elliott Hughes7f3a2722014-04-01 12:40:00 -070013#include <sys/types.h>
Ben Cheng21eab512012-03-13 23:04:57 -070014
Elliott Hughes7f3a2722014-04-01 12:40:00 -070015typedef enum {
Elliott Hughes5702c6f2017-08-31 17:27:05 -070016 FIND,
17 ENTER
18} ACTION;
19
20typedef struct entry {
21 char* key;
22 void* data;
23} ENTRY;
24
25typedef enum {
Elliott Hughes7f3a2722014-04-01 12:40:00 -070026 preorder,
27 postorder,
28 endorder,
29 leaf
Ben Cheng21eab512012-03-13 23:04:57 -070030} VISIT;
31
Elliott Hughes5702c6f2017-08-31 17:27:05 -070032#if defined(__USE_BSD) || defined(__USE_GNU)
33struct hsearch_data {
34 struct __hsearch* __hsearch;
35};
Ben Cheng21eab512012-03-13 23:04:57 -070036#endif
37
38__BEGIN_DECLS
Elliott Hughes7f3a2722014-04-01 12:40:00 -070039
Elliott Hughesff26a162017-08-17 22:34:21 +000040void insque(void* __element, void* __previous) __INTRODUCED_IN(21);
41void remque(void* __element) __INTRODUCED_IN(21);
Elliott Hughesb9026412014-07-23 16:02:26 -070042
Elliott Hughes5702c6f2017-08-31 17:27:05 -070043int hcreate(size_t) __INTRODUCED_IN_FUTURE;
44void hdestroy(void) __INTRODUCED_IN_FUTURE;
45ENTRY* hsearch(ENTRY, ACTION) __INTRODUCED_IN_FUTURE;
46
47#if defined(__USE_BSD) || defined(__USE_GNU)
48int hcreate_r(size_t, struct hsearch_data*) __INTRODUCED_IN_FUTURE;
49void hdestroy_r(struct hsearch_data*) __INTRODUCED_IN_FUTURE;
50int hsearch_r(ENTRY, ACTION, ENTRY**, struct hsearch_data*) __INTRODUCED_IN_FUTURE;
51#endif
52
Elliott Hughesff26a162017-08-17 22:34:21 +000053void* lfind(const void* __key, const void* __base, size_t* __count, size_t __size, int (*__comparator)(const void*, const void*))
Josh Gao14adff12016-04-29 12:00:55 -070054 __INTRODUCED_IN(21);
Elliott Hughesff26a162017-08-17 22:34:21 +000055void* lsearch(const void* __key, void* __base, size_t* __count, size_t __size, int (*__comparator)(const void*, const void*))
Josh Gao14adff12016-04-29 12:00:55 -070056 __INTRODUCED_IN(21);
Elliott Hughes7f3a2722014-04-01 12:40:00 -070057
Elliott Hughesff26a162017-08-17 22:34:21 +000058void* tdelete(const void* __key, void** __root_ptr, int (*__comparator)(const void*, const void*)) __INTRODUCED_IN(16);
59void tdestroy(void* __root, void (*__free_fn)(void*)) __INTRODUCED_IN(16);
60void* tfind(const void* __key, void* const* __root_ptr, int (*__comparator)(const void*, const void*)) __INTRODUCED_IN(16);
61void* tsearch(const void* __key, void** __root_ptr, int (*__comparator)(const void*, const void*)) __INTRODUCED_IN(16);
62void twalk(const void* __root, void (*__visitor)(const void*, VISIT, int)) __INTRODUCED_IN(21);
Elliott Hughes7f3a2722014-04-01 12:40:00 -070063
Ben Cheng21eab512012-03-13 23:04:57 -070064__END_DECLS
65
Elliott Hughesff26a162017-08-17 22:34:21 +000066#endif