1 .\" Copyright (c) 2001 Tobias Weingartner
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
7 .\" 1. Redistributions of source code must retain the above copyright
8 .\" notice, this list of conditions and the following disclaimer.
9 .\" 2. Redistributions in binary form must reproduce the above copyright
10 .\" notice, this list of conditions and the following disclaimer in the
11 .\" documentation and/or other materials provided with the distribution.
12 .\" 3. The name of the author may not be used to endorse or promote products
13 .\" derived from this software without specific prior written permission.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 .\" $OpenBSD: hash.9,v 1.5 2003/04/17 05:08:39 jmc Exp $
44 .Nd general kernel hashing functions
48 .Fn hash32_buf "const void *buf" "size_t len" "uint32_t hash"
50 .Fn hash32_str "const void *buf" "uint32_t hash"
52 .Fn hash32_strn "const void *buf" "size_t len" "uint32_t hash"
54 .Fn hash32_stre "const void *buf" "int end" "const char **ep" "uint32_t hash"
56 .Fn hash32_strne "const void *buf" "size_t len" "int end" "const char **ep" "uint32_t hash"
58 .Fn jenkins_hash "const void *buf" "size_t len" "uint32_t hash"
60 .Fn jenkins_hash32 "const uint32_t *buf" "size_t count" "uint32_t hash"
62 .Fn murmur3_32_hash "const void *buf" "size_t len" "uint32_t hash"
64 .Fn murmur3_32_hash32 "const uint32_t *buf" "size_t count" "uint32_t hash"
68 functions are used to give a consistent and general interface to
69 a decent hashing algorithm within the kernel.
70 These functions can be used to hash
73 terminated strings, as well as blocks of memory.
77 argument is the length of the buffer in bytes.
80 argument is the length of the buffer in 32-bit words.
84 function is used as a general buffer hashing function.
87 is used to pass in the location, and
89 is the length of the buffer in bytes.
92 is used to extend an existing hash, or is passed the initial value
98 function is used to hash a
100 terminated string passed in
102 with initial hash value given in
109 function, except it also takes a
111 argument, which is the maximal length of the expected string.
117 functions are helper functions used by the kernel to hash pathname
119 These functions have the additional termination condition
120 of terminating when they find a character given by
122 in the string to be hashed.
127 it is set to the point in the buffer at which the hash function
132 function has same semantics as the
134 but provides more advanced hashing algorithm with better distribution.
138 uses same hashing algorithm as the
140 function, but works only on
142 sized arrays, thus is simpler and faster.
143 It accepts an array of
145 values in its first argument and size of this array in the second argument.
150 .Fn murmur3_32_hash32
151 functions are similar to
155 but implement the 32-bit version of MurmurHash3.
159 functions return a 32 bit hash value of the buffer or string.
161 .Bd -literal -offset indent
162 LIST_HEAD(head, cache) *hashtbl = NULL;
169 hashtbl = hashinit(numwanted, type, flags, &mask);
173 sample_use(char *str, int len)
177 hash = hash32_str(str, HASHINIT);
178 hash = hash32_buf(&len, sizeof(len), hash);
179 hashtbl[hash & mask] = len;
189 functions are only 32 bit functions.
190 They will prove to give poor 64 bit performance, especially for the
192 At the current time, this is not seen as a great limitation, as these
193 hash values are usually used to index into an array.
194 Should these hash values be used for other means, this limitation should
199 functions first appeared in
201 The current implementation of
203 functions was first committed to
205 and later imported to
209 functions were added in
213 functions were added in
218 functions were written by
219 .An Tobias Weingartner .
222 functions were written by
226 functions were written by
227 .An Dag-Erling Sm\(/orgrav Aq Mt des@FreeBSD.org .