Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/openjdk-multiarch-jdk8u
Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/agent/src/os/linux/hsearch/search.h
38841 views
1
/*-
2
* Written by J.T. Conklin <[email protected]>
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
#pragma once
9
/**
10
* @file search.h
11
* @brief Queues, hash tables, trees, and linear array searches.
12
*/
13
#include <sys/cdefs.h>
14
#include <sys/types.h>
15
/** See hsearch()/hsearch_r(). */
16
typedef enum {
17
FIND,
18
ENTER
19
} ACTION;
20
/** See hsearch()/hsearch_r(). */
21
typedef struct entry {
22
/** The string key. */
23
char* key;
24
/** The associated data. */
25
void* data;
26
} ENTRY;
27
/**
28
* Constants given to the twalk() visitor.
29
* Note that the constant names are misleading.
30
*/
31
typedef enum {
32
/**
33
* If this is the first visit to a non-leaf node.
34
* Use this for *preorder* traversal.
35
*/
36
preorder,
37
/**
38
* If this is the second visit to a non-leaf node.
39
* Use this for *inorder* traversal.
40
*/
41
postorder,
42
/**
43
* If this is the third visit to a non-leaf node.
44
* Use this for *postorder* traversal.
45
*/
46
endorder,
47
/** If this is the first and only visit to a leaf node. */
48
leaf
49
} VISIT;
50
// #if defined(__USE_BSD) || defined(__USE_GNU)
51
/** The hash table type for hcreate_r()/hdestroy_r()/hsearch_r(). */
52
struct hsearch_data {
53
struct __hsearch* __hsearch;
54
};
55
//#endif
56
__BEGIN_DECLS
57
/**
58
* [insque(3)](http://man7.org/linux/man-pages/man3/insque.3.html) inserts
59
* an item in a queue (an intrusive doubly-linked list).
60
*
61
* Available since API level 21.
62
*/
63
void insque(void* __element, void* __previous); // __INTRODUCED_IN(21);
64
/**
65
* [remque(3)](http://man7.org/linux/man-pages/man3/remque.3.html) removes
66
* an item from a queue (an intrusive doubly-linked list).
67
*
68
* Available since API level 21.
69
*/
70
void remque(void* __element); // __INTRODUCED_IN(21);
71
/**
72
* [hcreate(3)](http://man7.org/linux/man-pages/man3/hcreate.3.html)
73
* initializes the global hash table, with space for at least `__n` elements.
74
*
75
* See hcreate_r() if you need more than one hash table.
76
*
77
* Returns *non-zero* on success and returns 0 and sets `errno` on failure.
78
*
79
* Available since API level 28.
80
*/
81
int hcreate(size_t __n); // __INTRODUCED_IN(28);
82
/**
83
* [hdestroy(3)](http://man7.org/linux/man-pages/man3/hdestroy.3.html) destroys
84
* the global hash table.
85
*
86
* See hdestroy_r() if you need more than one hash table.
87
*
88
* Available since API level 28.
89
*/
90
void hdestroy(void); // __INTRODUCED_IN(28);
91
/**
92
* [hsearch(3)](http://man7.org/linux/man-pages/man3/hsearch.3.html) finds or
93
* inserts `__entry` in the global hash table, based on `__action`.
94
*
95
* See hsearch_r() if you need more than one hash table.
96
*
97
* Returns a pointer to the entry on success, and returns NULL and sets
98
* `errno` on failure.
99
*
100
* Available since API level 28.
101
*/
102
ENTRY* hsearch(ENTRY __entry, ACTION __action); // __INTRODUCED_IN(28);
103
// #if defined(__USE_BSD) || defined(__USE_GNU)
104
/**
105
* [hcreate_r(3)](http://man7.org/linux/man-pages/man3/hcreate_r.3.html)
106
* initializes a hash table `__table` with space for at least `__n` elements.
107
*
108
* Returns *non-zero* on success and returns 0 and sets `errno` on failure.
109
*
110
* Available since API level 28.
111
*/
112
int hcreate_r(size_t __n, struct hsearch_data* __table); // __INTRODUCED_IN(28);
113
/**
114
* [hdestroy_r(3)](http://man7.org/linux/man-pages/man3/hdestroy_r.3.html) destroys
115
* the hash table `__table`.
116
*
117
* Available since API level 28.
118
*/
119
void hdestroy_r(struct hsearch_data* __table); // __INTRODUCED_IN(28);
120
/**
121
* [hsearch_r(3)](http://man7.org/linux/man-pages/man3/hsearch_r.3.html) finds or
122
* inserts `__entry` in the hash table `__table`, based on `__action`.
123
*
124
* Returns *non-zero* on success and returns 0 and sets `errno` on failure.
125
* A pointer to the entry is returned in `*__result`.
126
*
127
* Available since API level 28.
128
*/
129
int hsearch_r(ENTRY __entry, ACTION __action, ENTRY** __result, struct hsearch_data* __table); // __INTRODUCED_IN(28);
130
// #endif
131
/**
132
* [lfind(3)](http://man7.org/linux/man-pages/man3/lfind.3.html) brute-force
133
* searches the unsorted array `__array` (of `__count` items each of size `__size`)
134
* for `__key`, using `__comparator`.
135
*
136
* See bsearch() if you have a sorted array.
137
*
138
* Returns a pointer to the matching element on success, or NULL on failure.
139
*
140
* Available since API level 21.
141
*/
142
void* lfind(const void* __key, const void* __array, size_t* __count, size_t __size, int (*__comparator)(const void*, const void*)); // __INTRODUCED_IN(21);
143
/**
144
* [lsearch(3)](http://man7.org/linux/man-pages/man3/lsearch.3.html) brute-force
145
* searches the unsorted array `__array` (of `__count` items each of size `__size`)
146
* for `__key`, using `__comparator`.
147
*
148
* Unlike lfind(), on failure lsearch() will *insert* `__key` at the end of
149
* `__array` and increment `*__count`.
150
*
151
* Returns a pointer to the matching element on success, or to the newly-added
152
* element on failure.
153
*
154
* Available since API level 21.
155
*/
156
void* lsearch(const void* __key, void* __array, size_t* __count, size_t __size, int (*__comparator)(const void*, const void*)); // __INTRODUCED_IN(21);
157
/**
158
* [tdelete(3)](http://man7.org/linux/man-pages/man3/tdelete.3.html) searches
159
* for and removes an element in the tree `*__root_ptr`. The search is performed
160
* using `__comparator`.
161
*
162
* Returns a pointer to the parent of the deleted node, or NULL on failure.
163
*/
164
void* tdelete(const void* __key, void** __root_ptr, int (*__comparator)(const void*, const void*));
165
/**
166
* [tdestroy(3)](http://man7.org/linux/man-pages/man3/tdestroy.3.html) destroys
167
* the hash table `__root` using `__free_fn` on each node.
168
*/
169
void tdestroy(void* __root, void (*__free_fn)(void*));
170
/**
171
* [tfind(3)](http://man7.org/linux/man-pages/man3/tfind.3.html) searches
172
* for an element in the tree `*__root_ptr`. The search is performed using
173
* `__comparator`.
174
*
175
* Returns a pointer to the matching node, or NULL on failure.
176
*/
177
void* tfind(const void* __key, void* const* __root_ptr, int (*__comparator)(const void*, const void*));
178
/**
179
* [tsearch(3)](http://man7.org/linux/man-pages/man3/tsearch.3.html) searches
180
* for an element in the tree `*__root_ptr`. The search is performed using
181
* `__comparator`.
182
*
183
* Unlike tfind(), on failure tsearch() will *insert* `__key` into the tree.
184
*
185
* Returns a pointer to the matching node, or to the newly-added node.
186
*/
187
void* tsearch(const void* __key, void** __root_ptr, int (*__comparator)(const void*, const void*));
188
/**
189
* [twalk(3)](http://man7.org/linux/man-pages/man3/twalk.3.html) calls
190
* `__visitor` on every node in the tree.
191
*/
192
void twalk(const void* __root, void (*__visitor)(const void*, VISIT, int)); // __INTRODUCED_IN(21);
193
__END_DECLS
194
195