Main index | Section 9 | Options |
#include <sys/hash.h>
A len argument is the length of the buffer in bytes. A count argument is the length of the buffer in 32-bit words.
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 in bytes. 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 string.
The hash32_stre() and hash32_strne() functions are helper functions used by the kernel to hash pathname components. These functions have the additional 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 terminated hashing.
The jenkins_hash() function has same semantics as the hash32_buf(), but provides more advanced hashing algorithm with better distribution.
The jenkins_hash32() uses same hashing algorithm as the jenkins_hash() function, but works only on uint32_t sized arrays, thus is simpler and faster. It accepts an array of uint32_t values in its first argument and size of this array in the second argument.
The murmur3_32_hash() and murmur3_32_hash32() functions are similar to jenkins_hash() and jenkins_hash32(), but implement the 32-bit version of MurmurHash3.
LIST_HEAD(head, cache) *hashtbl = NULL; u_long mask = 0;void sample_init(void) {
hashtbl = hashinit(numwanted, type, flags, &mask); }
void 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; }
HASH (9) | June 30, 2015 |
Main index | Section 9 | Options |
Please direct any comments about this manual page service to Ben Bullock. Privacy policy.
“ | One of the advantages of using UNIX to teach an operating systems course is the sources and documentation will easily fit into a student's briefcase. | ” |
— John Lions |