diff options
author | cvs2svn <admin@example.com> | 2025-04-14 17:32:06 +0000 |
---|---|---|
committer | cvs2svn <admin@example.com> | 2025-04-14 17:32:06 +0000 |
commit | eb8dd9dca1228af0cd132f515509051ecfabf6f6 (patch) | |
tree | edb6da6af7e865d488dc1a29309f1e1ec226e603 /src/lib/libc/stdlib/hcreate.3 | |
parent | 247f0352e0ed72a4f476db9dc91f4d982bc83eb2 (diff) | |
download | openbsd-tb_20250414.tar.gz openbsd-tb_20250414.tar.bz2 openbsd-tb_20250414.zip |
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to 'src/lib/libc/stdlib/hcreate.3')
-rw-r--r-- | src/lib/libc/stdlib/hcreate.3 | 234 |
1 files changed, 0 insertions, 234 deletions
diff --git a/src/lib/libc/stdlib/hcreate.3 b/src/lib/libc/stdlib/hcreate.3 deleted file mode 100644 index 90bde1995f..0000000000 --- a/src/lib/libc/stdlib/hcreate.3 +++ /dev/null | |||
@@ -1,234 +0,0 @@ | |||
1 | .\" $OpenBSD: hcreate.3,v 1.8 2018/01/30 11:37:58 jmc Exp $ | ||
2 | .\" $NetBSD: hcreate.3,v 1.8 2010/05/01 06:18:03 jruoho Exp $ | ||
3 | .\" | ||
4 | .\" Copyright (c) 1999 The NetBSD Foundation, Inc. | ||
5 | .\" All rights reserved. | ||
6 | .\" | ||
7 | .\" This code is derived from software contributed to The NetBSD Foundation | ||
8 | .\" by Klaus Klein. | ||
9 | .\" | ||
10 | .\" Redistribution and use in source and binary forms, with or without | ||
11 | .\" modification, are permitted provided that the following conditions | ||
12 | .\" are met: | ||
13 | .\" 1. Redistributions of source code must retain the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer. | ||
15 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
16 | .\" notice, this list of conditions and the following disclaimer in the | ||
17 | .\" documentation and/or other materials provided with the distribution. | ||
18 | .\" | ||
19 | .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS | ||
20 | .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
21 | .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
22 | .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | ||
23 | .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
24 | .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
25 | .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
26 | .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
27 | .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
28 | .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
29 | .\" POSSIBILITY OF SUCH DAMAGE. | ||
30 | .\" | ||
31 | .Dd $Mdocdate: January 30 2018 $ | ||
32 | .Dt HCREATE 3 | ||
33 | .Os | ||
34 | .Sh NAME | ||
35 | .Nm hcreate , | ||
36 | .Nm hdestroy , | ||
37 | .Nm hsearch | ||
38 | .Nd manage hash search table | ||
39 | .Sh SYNOPSIS | ||
40 | .In search.h | ||
41 | .Ft int | ||
42 | .Fn hcreate "size_t nel" | ||
43 | .Ft void | ||
44 | .Fn hdestroy "void" | ||
45 | .Ft ENTRY * | ||
46 | .Fn hsearch "ENTRY item" "ACTION action" | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Fn hcreate , | ||
50 | .Fn hdestroy , | ||
51 | and | ||
52 | .Fn hsearch | ||
53 | functions manage hash search tables. | ||
54 | .Pp | ||
55 | The | ||
56 | .Fn hcreate | ||
57 | function allocates and initializes the table. | ||
58 | The | ||
59 | .Fa nel | ||
60 | argument specifies an estimate of the maximum number of entries to be held | ||
61 | by the table. | ||
62 | Unless further memory allocation fails, supplying an insufficient | ||
63 | .Fa nel | ||
64 | value will not result in functional harm, although a performance degradation | ||
65 | may occur. | ||
66 | Initialization using the | ||
67 | .Fn hcreate | ||
68 | function is mandatory prior to any access operations using | ||
69 | .Fn hsearch . | ||
70 | .Pp | ||
71 | The | ||
72 | .Fn hdestroy | ||
73 | function destroys a table previously created using | ||
74 | .Fn hcreate . | ||
75 | After a call to | ||
76 | .Fn hdestroy , | ||
77 | the data can no longer be accessed. | ||
78 | .Pp | ||
79 | The | ||
80 | .Fn hsearch | ||
81 | function is used to search the hash table. | ||
82 | It returns a pointer into the | ||
83 | hash table indicating the address of an item. | ||
84 | The | ||
85 | .Fa item | ||
86 | argument is of type | ||
87 | .Vt ENTRY , | ||
88 | defined in the | ||
89 | .In search.h | ||
90 | header. | ||
91 | This is a structure type that contains two pointers: | ||
92 | .Pp | ||
93 | .Bl -tag -compact -offset indent -width "void *data " | ||
94 | .It Fa char *key | ||
95 | comparison key | ||
96 | .It Fa void *data | ||
97 | pointer to data associated with | ||
98 | .Fa key | ||
99 | .El | ||
100 | .Pp | ||
101 | The key comparison function used by | ||
102 | .Fn hsearch | ||
103 | is | ||
104 | .Xr strcmp 3 . | ||
105 | .Pp | ||
106 | The | ||
107 | .Fa action | ||
108 | argument is of type | ||
109 | .Vt ACTION , | ||
110 | an enumeration type which defines the following values: | ||
111 | .Bl -tag -offset indent -width ENTERXX | ||
112 | .It Dv ENTER | ||
113 | Insert | ||
114 | .Fa item | ||
115 | into the hash table. | ||
116 | If an existing item with the same key is found, it is not replaced. | ||
117 | Note that the | ||
118 | .Fa key | ||
119 | and | ||
120 | .Fa data | ||
121 | elements of | ||
122 | .Fa item | ||
123 | are used directly by the new table entry. | ||
124 | The storage for the | ||
125 | key must not be modified during the lifetime of the hash table. | ||
126 | .It Dv FIND | ||
127 | Search the hash table without inserting | ||
128 | .Fa item . | ||
129 | .El | ||
130 | .Pp | ||
131 | Note that the comparison | ||
132 | .Fa key | ||
133 | must be allocated using | ||
134 | .Xr malloc 3 | ||
135 | or | ||
136 | .Xr calloc 3 | ||
137 | if action is | ||
138 | .Dv ENTER | ||
139 | and | ||
140 | .Fn hdestroy | ||
141 | will be called. | ||
142 | This is because | ||
143 | .Fn hdestroy | ||
144 | will call | ||
145 | .Xr free 3 | ||
146 | for each comparison | ||
147 | .Fa key | ||
148 | (but not | ||
149 | .Fa data ) . | ||
150 | Typically the comparison | ||
151 | .Fa key | ||
152 | is allocated by using | ||
153 | .Xr strdup 3 . | ||
154 | .Sh RETURN VALUES | ||
155 | If successful, the | ||
156 | .Fn hcreate | ||
157 | function returns a non-zero value. | ||
158 | Otherwise, a value of 0 is returned and | ||
159 | .Va errno | ||
160 | is set to indicate the error. | ||
161 | .Pp | ||
162 | If successful, the | ||
163 | .Fn hsearch | ||
164 | function returns a pointer to a hash table entry matching | ||
165 | the provided key. | ||
166 | If the action is | ||
167 | .Dv FIND | ||
168 | and the item was not found, or if the action is | ||
169 | .Dv ENTER | ||
170 | and the insertion failed, | ||
171 | .Dv NULL | ||
172 | is returned and | ||
173 | .Va errno | ||
174 | is set to indicate the error. | ||
175 | If the action is | ||
176 | .Dv ENTER | ||
177 | and an entry already existed in the table matching the given | ||
178 | key, the existing entry is returned and is not replaced. | ||
179 | .Sh ERRORS | ||
180 | The | ||
181 | .Fn hcreate | ||
182 | and | ||
183 | .Fn hsearch | ||
184 | functions will fail if: | ||
185 | .Bl -tag -width Er | ||
186 | .It Bq Er ENOMEM | ||
187 | Insufficient memory is available. | ||
188 | .El | ||
189 | .Sh SEE ALSO | ||
190 | .Xr bsearch 3 , | ||
191 | .Xr lsearch 3 , | ||
192 | .Xr malloc 3 , | ||
193 | .Xr strcmp 3 | ||
194 | .Sh STANDARDS | ||
195 | The | ||
196 | .Fn hcreate , | ||
197 | .Fn hdestroy | ||
198 | and | ||
199 | .Fn hsearch | ||
200 | functions conform to | ||
201 | .St -xpg4.2 . | ||
202 | .Sh HISTORY | ||
203 | The | ||
204 | .Fn hcreate , | ||
205 | .Fn hdestroy | ||
206 | and | ||
207 | .Fn hsearch | ||
208 | functions first appeared in | ||
209 | .At V . | ||
210 | .Sh CAVEATS | ||
211 | At least the following limitations can be mentioned: | ||
212 | .Bl -bullet | ||
213 | .It | ||
214 | The interface permits the use of only one hash table at a time. | ||
215 | .It | ||
216 | Individual hash table entries can be added, but not deleted. | ||
217 | .It | ||
218 | The standard is indecipherable about the | ||
219 | internal memory usage of the functions, | ||
220 | mentioning only that | ||
221 | .Do | ||
222 | .Fn hcreate | ||
223 | and | ||
224 | .Fn hsearch | ||
225 | functions may use | ||
226 | .Fn malloc | ||
227 | to allocate space | ||
228 | .Dc . | ||
229 | This limits the portability of the functions, | ||
230 | given that other implementations may not | ||
231 | .Xr free 3 | ||
232 | the buffer pointed by | ||
233 | .Fa key . | ||
234 | .El | ||