1 .\" $NetBSD: hcreate.3,v 1.10 2011/09/15 09:14:54 wiz Exp $
3 .\" Copyright (c) 1999 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" This code is derived from software contributed to The NetBSD Foundation
9 .\" Redistribution and use in source and binary forms, with or without
10 .\" modification, are permitted provided that the following conditions
12 .\" 1. Redistributions of source code must retain the above copyright
13 .\" notice, this list of conditions and the following disclaimer.
14 .\" 2. Redistributions in binary form must reproduce the above copyright
15 .\" notice, this list of conditions and the following disclaimer in the
16 .\" documentation and/or other materials provided with the distribution.
18 .\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
19 .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20 .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
21 .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
22 .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 .\" POSSIBILITY OF SUCH DAMAGE.
30 .Dd September 14, 2011
40 .Nd manage hash search table
46 .Fn hcreate "size_t nel"
48 .Fn hcreate_r "size_t nel" "struct hsearch_data *table"
52 .Fn hdestroy_r "struct hsearch_data *table"
54 .Fn hsearch "ENTRY item" "ACTION action"
56 .Fn hsearch_r "ENTRY item" "ACTION action" "ENTRY ** itemp" "struct hsearch_data *table"
66 functions manage hash search tables.
70 function allocates and initializes the table.
73 argument specifies an estimate of the maximum number of entries to be held
75 Unless further memory allocation fails, supplying an insufficient
77 value will not result in functional harm, although a performance degradation
79 Initialization using the
81 function is mandatory prior to any access operations using
86 function destroys a table previously created using
90 the data can no longer be accessed.
94 function is used to search to the hash table.
95 It returns a pointer into the
96 hash table indicating the address of an item.
104 This is a structure type that contains two pointers:
106 .Bl -tag -compact -offset indent -width "void *data "
110 pointer to data associated with
114 The key comparison function used by
123 an enumeration type which defines the following values:
124 .Bl -tag -offset indent -width ENTERXX
129 If an existing item with the same key is found, it is not replaced.
136 are used directly by the new table entry.
138 key must not be modified during the lifetime of the hash table.
140 Search the hash table without inserting
144 Note that the comparison
146 must be allocated using
163 Typically the comparison
165 is allocated by using
173 functions are re-entrant versions of the above functions that can
174 operate on a table supplied by the user.
181 and the element cannot be created,
184 If the element exists or can be created, it will be placed in
195 functions return a non-zero value.
196 Otherwise, a value of
200 is set to indicate the error.
206 functions return no value.
210 function returns a pointer to hash table entry matching
214 and the item was not found, or if the action is
216 and the insertion failed,
220 is set to indicate the error.
223 and an entry already existed in the table matching the given
224 key, the existing entry is returned and is not replaced.
230 unless the table is full, when it returns
236 or the element is not found,
238 is set to indicate the error.
246 functions will fail if:
249 Insufficient memory is available.
256 functions will also fail if the action is
258 and the element is not found:
284 functions first appeared in
295 At least the following limitations can be mentioned:
300 interface permits the use of only one hash table at a time.
302 Individual hash table entries can be added, but not deleted.
304 The standard is indecipherable about the
305 internal memory usage of the functions,
315 This limits the portability of the functions,
316 given that other implementations may not
318 the buffer pointed by