Shadow Network Framework  0.0.1-alpha
C Server Library for Shadow Network Framework
Loading...
Searching...
No Matches
locate3.h
Go to the documentation of this file.
1////////////////////////////////////////////////////////////////////
2///
3/// \file locate3.h
4/// All the code in lookup3.c is written by Bob Jenkins, May 2006.
5/// this header file is written by acording to locate3.c
6///
7///////////////////////////////////////////////////////////////////
8
9#ifndef locate3_h
10#define locate3_h
11#include <stdint.h>
12#include <stdio.h>
13
14/// @brief hash a variable-length key into a 32-bit value
15/*! @fn
16* hashlittle() -- hash a variable-length key into a 32-bit value <br>
17* **k** : the key (the unaligned variable-length array of bytes) <br>
18* **length** : the length of the key, counting by bytes <br>
19* **initval** : can be any 4-byte value <br>
20* Returns a 32-bit value. Every bit of the key affects every bit of
21* the return value. Two keys differing by one or two bits will have
22* totally different hash values.
23*
24* The best hash table sizes are powers of 2. There is no need to do
25* mod a prime (mod is sooo slow!). If you need less than 32 bits,
26* use a bitmask. For example, if you need only 10 bits, do
27* __h = (h & hashmask(10));__ <br>
28* In which case, the hash table should have hashsize(10) elements. <br>
29* <br>
30* If you are hashing n strings (uint8_t **)k, do it like this: <br>
31*
32* for (i=0, h=0; i<n; ++i) h = hashlittle( k[i], len[i], h);
33*/
34/*! @note
35* Made by Bob Jenkins, 2006. bob_jenkins@burtleburtle.net. <br>
36* Use for hash table lookup, or anything where one collision in 2^^32 is
37* acceptable. Do NOT use for cryptographic purposes.
38*/
39extern uint32_t hashlittle(const void *key, size_t length, uint32_t initval);
40/// @brief return 2 32-bit hash values
41/*! @fn
42 * hashlittle2: return 2 32-bit hash values
43 *
44 * This is identical to hashlittle(), except it returns two 32-bit hash
45 * values instead of just one. This is good enough for hash table
46 * lookup with 2^^64 buckets, or if you want a second hash if you're not
47 * happy with the first, or if you want a probably-unique 64-bit ID for
48 * the key. *pc is better mixed than *pb, so use *pc first. If you want
49 * a 64-bit value do something like __"*pc + (((uint64_t)*pb)<<32)"__.
50 */
51/*! @note
52* Made by Bob Jenkins, 2006. bob_jenkins@burtleburtle.net. <br>
53* Use for hash table lookup, or anything where one collision in 2^^32 is
54* acceptable. Do NOT use for cryptographic purposes.
55*/
56extern void hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb);
57/*! @fn
58 * hashbig():
59 * This is the same as hashword() on big-endian machines. It is different
60 * from hashlittle() on all machines. hashbig() takes advantage of
61 * big-endian byte ordering.
62 */
63/*! @note
64* Made by Bob Jenkins, 2006. bob_jenkins@burtleburtle.net. <br>
65* Use for hash table lookup, or anything where one collision in 2^^32 is
66* acceptable. Do NOT use for cryptographic purposes.
67*/
68extern uint32_t hashbig( const void *key, size_t length, uint32_t initval);
69#endif
uint32_t hashbig(const void *key, size_t length, uint32_t initval)
void hashlittle2(const void *key, size_t length, uint32_t *pc, uint32_t *pb)
return 2 32-bit hash values
uint32_t hashlittle(const void *key, size_t length, uint32_t initval)
hash a variable-length key into a 32-bit value