MirOS Manual: hash(9)

HASH(9)                       BSD Kernel Manual                        HASH(9)


     hash - general kernel hashing functions


     #include <sys/hash.h>

     hash32_buf(void *buf, size_t len, uint32_t hash);

     hash32_str(void *buf, uint32_t hash);

     hash32_strn(void *buf, size_t len, uint32_t hash);

     hash32_stre(void *buf, int end, char **ep, uint32_t hash);

     hash32_strne(void *buf, size_t len, int end, char **ep, uint32_t hash);


     The hash32() functions are used to give a consistent and general inter-
     face to a decent hashing algorithm within the kernel. These functions can
     be used to hash ASCII NUL terminated strings, as well as blocks of

     The hash32_buf() function is used as a general buffer hashing function.
     The argument buf is used to pass in the location, and len is the length
     of the buffer. The argument hash is used to extend an existing hash, or
     is passed the initial value HASHINIT to start a new hash.

     The hash32_str() function is used to hash a NUL terminated string passed
     in buf with initial hash value given in hash.

     The hash32_strn() function is like the hash32_str() function, except it
     also takes a len argument, which is the maximal length of the expected

     The hash32_stre() and hash32_strne() functions are helper functions used
     by the kernel to hash pathname components. These functions have the addi-
     tional termination condition of terminating when they find a character
     given by end in the string to be hashed. If the argument ep is not NULL,
     it is set to the point in the buffer at which the hash function terminat-
     ed hashing.


     The hash32() functions return a 32 bit hash value of the buffer or


           LIST_HEAD(head, cache) *hashtbl = NULL;
           u_long mask = 0;

                   hashtbl = hashinit(numwanted, type, flags, &mask);

           sample_use(char *str, int len)
                   uint32_t hash;
                   hash = hash32_str(str, HASHINIT);
                   hash = hash32_buf(&len, sizeof(len), hash);
                   hashtbl[hash & mask] = len;


     free(9), hashinit(9), malloc(9)


     The hash32() functions are only 32 bit functions. They will prove to give
     poor 64 bit performance, especially for the top 32 bits. At the current
     time, this is not seen as a great limitation, as these hash values are
     usually used to index into an array. Should these hash values be used for
     other means, this limitation should be revisited.


     The hash functions were first committed to NetBSD 1.6. The OpenBSD ver-
     sions were written and massaged for OpenBSD 2.3 by Tobias Weingartner,
     and finally committed for OpenBSD 3.2.

MirOS BSD #10-current          December 8, 2001                              1

Generated on 2017-04-03 16:26:17 by $MirOS: src/scripts/roff2htm,v 1.88 2017/01/29 00:51:06 tg Exp $

These manual pages and other documentation are copyrighted by their respective writers; their source is available at our CVSweb, AnonCVS, and other mirrors. The rest is Copyright © 2002–2017 The MirOS Project, Germany.
This product includes material provided by mirabilos.

This manual page’s HTML representation is supposed to be valid XHTML/1.1; if not, please send a bug report — diffs preferred.