1.\" Copyright (c) 2003-2004 Hiten Pandya <hmp@backplane.com> 2.\" 3.\" All rights reserved. 4.\" 5.\" Redistribution and use in source and binary forms, with or without 6.\" modification, are permitted provided that the following conditions 7.\" are met: 8.\" 9.\" 1. Redistributions of source code must retain the above copyright 10.\" notice, this list of conditions and the following disclaimer. 11.\" 12.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" notice, this list of conditions and the following disclaimer in 14.\" the documentation and/or other materials provided with the 15.\" distribution. 16.\" 17.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 20.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 21.\" COPYRIGHT HOLDERS, CONTRIBUTORS OR VOICES IN HITEN PANDYA'S HEAD 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY 23.\" OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 24.\" OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 25.\" BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 26.\" WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 27.\" OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 28.\" EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29.\" 30.\" $DragonFly: src/share/man/man9/hash.9,v 1.1 2004/05/14 18:11:44 hmp Exp $ 31.\" 32.Dd May 14, 2004 33.Os 34.Dt HASH 9 35.Sh NAME 36.Nm hash , 37.Nm hashinit , 38.Nm phashinit 39.Nd generic hash table functions for the kernel 40.Sh SYNOPSIS 41.In sys/param.h 42.In sys/systm.h 43.In sys/malloc.h 44.Ft void * 45.Fn hashinit "int elements" "struct malloc_type *type" "u_long *hashmask" 46.Ft void * 47.Fn phashinit "int elements" "struct malloc_type *type" "u_long *nentries" 48.Sh DESCRIPTION 49The kernel hash functions are used for creating a generic hash table. 50.Pp 51The 52.Fn hashinit 53function returns a pointer to a hash table which is sized a 54.Dq "power of two" 55greater or equal to the number of 56.Fa elements 57requested. 58The masking value is stored in 59.Fa hashmask . 60.Pp 61The 62.Fn phashinit 63function returns a pointer to a prime number sized hash table. 64The number of 65.Fa elements 66requested is used to dictate an upper-bound for the size of the 67hash table. 68The final size of the hash table is stored by the function in 69.Fa nentries . 70.Pp 71The 72.Fa type 73argument to both of the above functions is used for keeping track 74of memory allocated for the hash table. 75See the 76.Xr malloc 9 77manual page for more information on memory statistics. 78.Sh CODE REFERENCES 79The VFS namecache code is one of many examples for using the 80.Fn hashinit 81function; it is located within the file 82.Pa sys/kern/vfs_cache.c . 83.Pp 84The hostcache code uses the 85.Fn phashinit 86function for creating a prime number sized hash table; it is located 87within the file 88.Pa sys/net/hostcache.c . 89.Pp 90All pathnames in this section are relative to the 91.Dx 92source tree. 93.Sh SEE ALSO 94.Xr tcp 4 , 95.Xr udp 4 , 96.Xr malloc 9 , 97.Xr namei 9 98.Sh AUTHORS 99This manual page was written by 100.An Hiten Pandya Aq hmp@backplane.com . 101