1 .\" $NetBSD: hashinit.9,v 1.6 2008/05/27 22:03:52 hubertf Exp $
3 .\" Copyright (c) 2006 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.
36 .Nd kernel hash table construction and destruction
42 .Fa "enum hashtype htype"
44 .Fa "u_long *hashmask"
47 .Fn hashdone "void *hashtbl" "enum hashtype htype" "u_long hashmask"
51 function allocates and initializes space for a simple chaining hash table.
52 The number of slots will be the least power of two not smaller than
54 The customary choice for
56 is the maximum number of elements you intend to store divided by
57 your intended load factor.
64 can be used to manipulate the chains; pass
70 to indicate which. Each slot will be initialized as the head of an empty
71 chain of the proper type. Because different data structures from
73 can define head structures of different sizes, the total size of the
74 allocated table can vary with the choice of
81 can wait until enough memory is available.
82 Otherwise, it immediately fails if there is not enough memory is available.
84 A value will be stored into
86 suitable for masking any computed hash, to obtain the index of a chain
87 head in the allocated table.
91 function deallocates the storage allocated by
99 that were passed to and returned from
101 If the table contains any nonempty chain when
103 is called, the result is undefined.
105 The value returned by
107 should be cast as pointer to an array of
121 These functions are implemented in
122 .Pa sys/kern/subr_hash.c .
126 function was present, without the
132 It was independent of
134 and simply allocated and nulled a table of pointer-sized slots.
135 It sized the table to the
140 that is, it built in a load factor between 1 and 2.
148 It resembled that from
156 it had been changed to size the table to the least power of two
164 argument and the current sizing rule.
183 with behavior equivalent (as of
191 but checks that all chains are empty first.
199 This manual page was added for
202 The only part of the work of implementing a hash table that these functions
203 relieve is the part that isn't much work.