1 .\" $NetBSD: hcreate.3,v 1.6 2003/04/16 13:34:46 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.
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.
89 a structural type which contains the following members:
90 .Bl -tag -compact -offset indent -width voidX*dataXX
94 pointer to data associated with
98 The key comparison function used by
107 an enumeration type which defines the following values:
108 .Bl -tag -compact -offset indent -width ENTERXX
113 If an existing item with the same key is found, it is not replaced.
120 are used directly by the new table entry.
122 key must not be modified during the lifetime of the hash table.
124 Search the hash table without inserting
130 function returns a non-zero value.
131 Otherwise, a value of 0 is returned and
133 is set to indicate the error.
142 function returns a pointer to hash table entry matching
146 and the item was not found, or if the action is
148 and the insertion failed,
152 is set to indicate the error.
155 and an entry already existed in the table matching the given
156 key, the existing entry is returned and is not replaced.
162 functions will fail if:
165 Insufficient memory is available.
186 functions first appeared in
189 The interface permits the use of only one hash table at a time.