1 .\" $NetBSD: hcreate.3,v 1.8 2010/05/01 06:18:03 jruoho 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.
37 .Nd manage hash search table
43 .Fn hcreate "size_t nel"
47 .Fn hsearch "ENTRY item" "ACTION action"
54 functions manage hash search tables.
58 function allocates and initializes the table.
61 argument specifies an estimate of the maximum number of entries to be held
63 Unless further memory allocation fails, supplying an insufficient
65 value will not result in functional harm, although a performance degradation
67 Initialization using the
69 function is mandatory prior to any access operations using
74 function destroys a table previously created using
78 the data can no longer be accessed.
82 function is used to search to the hash table.
83 It returns a pointer into the
84 hash table indicating the address of an item.
92 This is a structure type that contains two pointers:
94 .Bl -tag -compact -offset indent -width "void *data "
98 pointer to data associated with
102 The key comparison function used by
111 an enumeration type which defines the following values:
112 .Bl -tag -offset indent -width ENTERXX
117 If an existing item with the same key is found, it is not replaced.
124 are used directly by the new table entry.
126 key must not be modified during the lifetime of the hash table.
128 Search the hash table without inserting
132 Note that the comparison
134 must be allocated using
151 Typically the comparison
153 is allocated by using
158 function returns a non-zero value.
159 Otherwise, a value of 0 is returned and
161 is set to indicate the error.
170 function returns a pointer to hash table entry matching
174 and the item was not found, or if the action is
176 and the insertion failed,
180 is set to indicate the error.
183 and an entry already existed in the table matching the given
184 key, the existing entry is returned and is not replaced.
190 functions will fail if:
193 Insufficient memory is available.
214 functions first appeared in
217 At least the following limitations can be mentioned:
220 The interface permits the use of only one hash table at a time.
222 Individual hash table entries can be added, but not deleted.
224 The standard is indecipherable about the
225 internal memory usage of the functions,
235 This limits the portability of the functions,
236 given that other implementations may not
238 the buffer pointed by