12.07.2015 Views

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

INTRO (9) NetBSD Kernel Developer's Manual INTRO (9) NAME ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

HASHINIT (9) <strong>NetBSD</strong> <strong>Kernel</strong> Developer’s <strong>Manual</strong> HASHINIT (9)<strong>NAME</strong>hashinit, hashdone —kernel hash table construction and destructionSYNOPSIS#include void ∗hashinit(u_int chains , enum hashtype htype , bool waitok , u_long ∗hashmask );voidhashdone(void ∗hashtbl , enum hashtype htype , u_long hashmask);DESCRIPTIONThe hashinit() function allocates and initializes space for a simple chaining hash table. The number ofslots will be the least power of two not smaller than chains. The customary choice for chains is themaximum number of elements you intend to store divided by your intended load factor. The LIST... orTAILQ... macros of queue(3) can be used to manipulate the chains; pass HASH_LIST or HASH_TAILQas htype to indicate which. Each slot will be initialized as the head of an empty chain of the proper type.Because different data structures from queue(3) can define head structures of different sizes, the total sizeof the allocated table can vary with the choice of htype.If waitok is true, hashinit can wait until enough memory is available. Otherwise, it immediately fails ifthere is not enough memory is available.Avalue will be stored into ∗hashmask suitable for masking any computed hash, to obtain the index ofachain head in the allocated table.The hashdone() function deallocates the storage allocated by hashinit() and pointed to by hashtbl,given the same htype and hashmask that were passed to and returned from hashinit(). If the tablecontains any nonempty chain when hashdone() is called, the result is undefined.RETURN VALUESThe value returned by hashinit() should be cast as pointer to an array of LIST_HEAD or TAILQ_HEADas appropriate. hashinit() returns NULL on failure.SEE ALSOqueue(3), hash(9), malloc(9)CODE REFERENCESThese functions are implemented in sys/kern/kern_hash.c.HISTORYA hashinit() function was present, without the htype or mflags arguments, in 4.4BSD alpha. It wasindependent of queue(3) and simply allocated and nulled a table of pointer-sized slots. It sized the table tothe largest power of two not greater than chains; that is, it built in a load factor between 1 and 2.<strong>NetBSD</strong> 1.0 was the first <strong>NetBSD</strong> release to have a hashinit() function. It resembled that from 4.4BSD butmade each slot a LIST_HEAD from queue(3). For <strong>NetBSD</strong> 1.3.3 it had been changed to size the table tothe least power of two not less than or equal to chains. By <strong>NetBSD</strong> 1.4 it had the mflags argument andthe current sizing rule.<strong>NetBSD</strong> 1.5 had the hashdone() function. By <strong>NetBSD</strong> 1.6 hashinit() supported LIST or TAILQ chainsselected with htype.<strong>NetBSD</strong> 3.0 May 28, 2008 1

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!