.\" .\" Copyright (c) 2003, 2004 The DragonFly Project. All rights reserved. .\" .\" This code is derived from software contributed to The DragonFly Project .\" by Hiten Pandya . .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in .\" the documentation and/or other materials provided with the .\" distribution. .\" 3. Neither the name of The DragonFly Project nor the names of its .\" contributors may be used to endorse or promote products derived .\" from this software without specific, prior written permission. .\" .\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT .\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS .\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE .\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, .\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING, .\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; .\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED .\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, .\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT .\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" .\" $DragonFly: src/share/man/man9/hash.9,v 1.3 2004/07/16 05:04:36 hmp Exp $ .\" .Dd May 14, 2004 .Os .Dt HASH 9 .Sh NAME .Nm hash , .Nm hashinit , .Nm phashinit .Nd generic hash table functions for the kernel .Sh SYNOPSIS .In sys/param.h .In sys/systm.h .In sys/malloc.h .Ft void * .Fn hashinit "int elements" "struct malloc_type *type" "u_long *hashmask" .Ft void * .Fn phashinit "int elements" "struct malloc_type *type" "u_long *nentries" .Sh DESCRIPTION The kernel hash functions are used for creating a generic hash table. .Pp The .Fn hashinit function returns a pointer to a hash table which is sized a .Dq "power of two" greater or equal to the number of .Fa elements requested. The masking value is stored in .Fa hashmask . .Pp The .Fn phashinit function returns a pointer to a prime number sized hash table. The number of .Fa elements requested is used to dictate an upper-bound for the size of the hash table. The final size of the hash table is stored by the function in .Fa nentries . .Pp The .Fa type argument to both of the above functions is used for keeping track of memory allocated for the hash table. See the .Xr malloc 9 manual page for more information on memory statistics. .Sh CODE REFERENCES The VFS namecache code is one of many examples for using the .Fn hashinit function; it is located within the file .Pa sys/kern/vfs_cache.c . .Pp The hostcache code uses the .Fn phashinit function for creating a prime number sized hash table; it is located within the file .Pa sys/net/hostcache.c . .Pp All pathnames in this section are relative to the .Dx source tree. .Sh SEE ALSO .Xr tcp 4 , .Xr udp 4 , .Xr malloc 9 , .Xr namei 9 .Sh AUTHORS This manual page was written by .An Hiten Pandya Aq hmp@backplane.com .