1 .\" $NetBSD: hcreate.3,v 1.13 2014/07/20 20:17:21 christos 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.
42 .Nd manage hash search table
48 .Fn hcreate "size_t nel"
50 .Fn hcreate_r "size_t nel" "struct hsearch_data *table"
54 .Fn hdestroy1 "void (*freekey)(void *)" "void (*freedata)(void *)"
56 .Fn hdestroy_r "struct hsearch_data *table"
58 .Fn hdestroy1_r "struct hsearch_data *table" "void (*freekey)(void *)" "void (*freedata)(void *)"
60 .Fn hsearch "ENTRY item" "ACTION action"
62 .Fn hsearch_r "ENTRY item" "ACTION action" "ENTRY ** itemp" "struct hsearch_data *table"
74 functions manage hash search tables.
78 function allocates and initializes the table.
81 argument specifies an estimate of the maximum number of entries to be held
83 Unless further memory allocation fails, supplying an insufficient
85 value will not result in functional harm, although a performance degradation
87 Initialization using the
89 function is mandatory prior to any access operations using
94 function destroys a table previously created using
98 the data can no longer be accessed.
102 function is used to search to the hash table.
103 It returns a pointer into the
104 hash table indicating the address of an item.
112 This is a structure type that contains two pointers:
114 .Bl -tag -compact -offset indent -width "void *data "
118 pointer to data associated with
122 The key comparison function used by
131 an enumeration type which defines the following values:
132 .Bl -tag -offset indent -width ENTERXX
137 If an existing item with the same key is found, it is not replaced.
144 are used directly by the new table entry.
146 key must not be modified during the lifetime of the hash table.
148 Search the hash table without inserting
158 the data associated with the
162 of each entry, because they did not allocate them.
165 function provided, the
169 allow controlling how the
173 will be freed using the
174 provided functions in the
193 functions are re-entrant versions of the above functions that can
194 operate on a table supplied by the user.
201 and the element cannot be created,
204 If the element exists or can be created, it will be placed in
215 functions return a non-zero value.
216 Otherwise, a value of
220 is set to indicate the error.
226 functions return no value.
230 function returns a pointer to hash table entry matching
234 and the item was not found, or if the action is
236 and the insertion failed,
240 is set to indicate the error.
243 and an entry already existed in the table matching the given
244 key, the existing entry is returned and is not replaced.
250 unless the table is full, when it returns
256 or the element is not found,
258 is set to indicate the error.
266 functions will fail if:
269 Insufficient memory is available.
276 functions will also fail if the action is
278 and the element is not found:
305 functions first appeared in
323 At least the following limitations can be mentioned:
328 interface permits the use of only one hash table at a time.
330 Individual hash table entries can be added, but not deleted.
332 There is no iterator to scan for all entries in the table.