xref: /dflybsd-src/share/man/man9/hashinit.9 (revision c616d3786462c4bbb32602d276dfb62c4d97ef77)
164377c51SSascha Wildner.\"
264377c51SSascha Wildner.\" Copyright (c) 2003, 2004 The DragonFly Project.  All rights reserved.
364377c51SSascha Wildner.\"
464377c51SSascha Wildner.\" This code is derived from software contributed to The DragonFly Project
564377c51SSascha Wildner.\" by Hiten Pandya <hmp@backplane.com>.
664377c51SSascha Wildner.\"
764377c51SSascha Wildner.\" Redistribution and use in source and binary forms, with or without
864377c51SSascha Wildner.\" modification, are permitted provided that the following conditions
964377c51SSascha Wildner.\" are met:
1064377c51SSascha Wildner.\"
1164377c51SSascha Wildner.\" 1. Redistributions of source code must retain the above copyright
1264377c51SSascha Wildner.\"    notice, this list of conditions and the following disclaimer.
1364377c51SSascha Wildner.\" 2. Redistributions in binary form must reproduce the above copyright
1464377c51SSascha Wildner.\"    notice, this list of conditions and the following disclaimer in
1564377c51SSascha Wildner.\"    the documentation and/or other materials provided with the
1664377c51SSascha Wildner.\"    distribution.
1764377c51SSascha Wildner.\" 3. Neither the name of The DragonFly Project nor the names of its
1864377c51SSascha Wildner.\"    contributors may be used to endorse or promote products derived
1964377c51SSascha Wildner.\"    from this software without specific, prior written permission.
2064377c51SSascha Wildner.\"
2164377c51SSascha Wildner.\" THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2264377c51SSascha Wildner.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2364377c51SSascha Wildner.\" LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2464377c51SSascha Wildner.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
2564377c51SSascha Wildner.\" COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2664377c51SSascha Wildner.\" INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
2764377c51SSascha Wildner.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2864377c51SSascha Wildner.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
2964377c51SSascha Wildner.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3064377c51SSascha Wildner.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3164377c51SSascha Wildner.\" OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3264377c51SSascha Wildner.\" SUCH DAMAGE.
3364377c51SSascha Wildner.\"
34add23450SSascha Wildner.Dd June 6, 2012
3564377c51SSascha Wildner.Dt HASHINIT 9
3664377c51SSascha Wildner.Os
3764377c51SSascha Wildner.Sh NAME
3864377c51SSascha Wildner.Nm hashinit ,
3964377c51SSascha Wildner.Nm hashinit_ext ,
40add23450SSascha Wildner.Nm hashdestroy ,
4164377c51SSascha Wildner.Nm phashinit ,
4264377c51SSascha Wildner.Nm phashinit_ext
4364377c51SSascha Wildner.Nd generic hash table functions for the kernel
4464377c51SSascha Wildner.Sh SYNOPSIS
4564377c51SSascha Wildner.In sys/param.h
4664377c51SSascha Wildner.In sys/systm.h
4764377c51SSascha Wildner.In sys/malloc.h
4864377c51SSascha Wildner.Ft void *
4964377c51SSascha Wildner.Fn hashinit "int count" "struct malloc_type *type" "u_long *hashmask"
5064377c51SSascha Wildner.Ft void *
5164377c51SSascha Wildner.Fn hashinit_ext "int count" "size_t size" "struct malloc_type *type" "u_long *hashmask"
52add23450SSascha Wildner.Ft void
53add23450SSascha Wildner.Fn hashdestroy "void *hashtbl" "struct malloc_type *type" "u_long hashmask"
5464377c51SSascha Wildner.Ft void *
5564377c51SSascha Wildner.Fn phashinit "int count" "struct malloc_type *type" "u_long *nentries"
5664377c51SSascha Wildner.Ft void *
5764377c51SSascha Wildner.Fn phashinit_ext "int count" "size_t size" "struct malloc_type *type" "u_long *nentries"
5864377c51SSascha Wildner.Sh DESCRIPTION
5964377c51SSascha WildnerThe kernel hash functions are used for creating a generic hash table.
6064377c51SSascha Wildner.Pp
6164377c51SSascha WildnerThe
6264377c51SSascha Wildner.Fn hashinit
6364377c51SSascha Wildnerfunction returns a pointer to a hash table which is sized a
6464377c51SSascha Wildner.Dq "power of two"
6564377c51SSascha Wildnergreater or equal to the element
6664377c51SSascha Wildner.Fa count
6764377c51SSascha Wildnerrequested.
6864377c51SSascha WildnerThe masking value is stored in
6964377c51SSascha Wildner.Fa hashmask .
7064377c51SSascha Wildner.Pp
7164377c51SSascha WildnerThe
7264377c51SSascha Wildner.Fn phashinit
7364377c51SSascha Wildnerfunction returns a pointer to a prime number sized hash table.
7464377c51SSascha WildnerThe element
7564377c51SSascha Wildner.Fa count
7664377c51SSascha Wildnerrequested is used to dictate an upper-bound for the size of the
7764377c51SSascha Wildnerhash table.
7864377c51SSascha WildnerThe final size of the hash table is stored by the function in
7964377c51SSascha Wildner.Fa nentries .
8064377c51SSascha Wildner.Pp
8164377c51SSascha WildnerThe
8264377c51SSascha Wildner.Fa type
8364377c51SSascha Wildnerargument to both of the above functions is used for keeping track
8464377c51SSascha Wildnerof memory allocated for the hash table.
8564377c51SSascha WildnerSee the
8664377c51SSascha Wildner.Xr kmalloc 9
8764377c51SSascha Wildnermanual page for more information on memory statistics.
8864377c51SSascha Wildner.Pp
8964377c51SSascha WildnerThe
9064377c51SSascha Wildner.Fn hashinit_ext
9164377c51SSascha Wildnerand
9264377c51SSascha Wildner.Fn phashinit_ext
9364377c51SSascha Wildnerfunctions are extended versions of
9464377c51SSascha Wildner.Fn hashinit
9564377c51SSascha Wildnerand
9664377c51SSascha Wildner.Fn phashinit
9764377c51SSascha Wildnerwhich take the
9864377c51SSascha Wildner.Fa size
9964377c51SSascha Wildnerof the structure as an additional argument and will zero the array instead
10064377c51SSascha Wildnerof assuming that it is an array of
10164377c51SSascha Wildner.Dv LIST_HEAD Ns s .
102add23450SSascha Wildner.Pp
103add23450SSascha WildnerThe
104add23450SSascha Wildner.Fn hashdestroy
105add23450SSascha Wildnerfunction frees the space occupied by the hash table pointed to by argument
106add23450SSascha Wildner.Fa hashtbl .
107add23450SSascha WildnerArgument
108add23450SSascha Wildner.Fa type
109add23450SSascha Wildnerdetermines the malloc arena to use when freeing space.
110add23450SSascha WildnerThe argument
111add23450SSascha Wildner.Fa hashmask
112add23450SSascha Wildnershould be the bit mask returned by the call to
113add23450SSascha Wildner.Fn hashinit
114add23450SSascha Wildnerthat allocated the hash table.
115add23450SSascha WildnerThe argument
116add23450SSascha Wildner.Fa flags
117add23450SSascha Wildnermust be used with one of the following values.
11864377c51SSascha Wildner.Sh SEE ALSO
11964377c51SSascha Wildner.Xr tcp 4 ,
12064377c51SSascha Wildner.Xr udp 4 ,
12164377c51SSascha Wildner.Xr kmalloc 9 ,
12264377c51SSascha Wildner.Xr nlookup 9
12364377c51SSascha Wildner.Sh AUTHORS
12464377c51SSascha WildnerThis manual page was written by
125*c616d378SFranco Fichtner.An Hiten Pandya Aq Mt hmp@backplane.com .
126add23450SSascha Wildner.Sh BUGS
127add23450SSascha WildnerThere is no
128add23450SSascha Wildner.Fn phashdestroy
129add23450SSascha Wildnerfunction, and using
130add23450SSascha Wildner.Fn hashdestroy
131add23450SSascha Wildnerto free a hash table allocated by
132add23450SSascha Wildner.Fn phashinit
133add23450SSascha Wildnerusually has grave consequences.
134