Shadow Network Framework  0.0.1-alpha
C Server Library for Shadow Network Framework
Loading...
Searching...
No Matches
locate3.h File Reference

All the code in lookup3.c is written by Bob Jenkins, May 2006. this header file is written by acording to locate3.c. More...

Go to the source code of this file.

Functions

uint32_t hashlittle (const void *key, size_t length, uint32_t initval)
 hash a variable-length key into a 32-bit value
 
void hashlittle2 (const void *key, size_t length, uint32_t *pc, uint32_t *pb)
 return 2 32-bit hash values
 
uint32_t hashbig (const void *key, size_t length, uint32_t initval)
 

Detailed Description

All the code in lookup3.c is written by Bob Jenkins, May 2006. this header file is written by acording to locate3.c.

Function Documentation

◆ hashlittle()

uint32_t hashlittle ( const void * key,
size_t length,
uint32_t initval )
extern

hash a variable-length key into a 32-bit value

hashlittle() – hash a variable-length key into a 32-bit value
k : the key (the unaligned variable-length array of bytes)
length : the length of the key, counting by bytes
initval : can be any 4-byte value
Returns a 32-bit value. Every bit of the key affects every bit of the return value. Two keys differing by one or two bits will have totally different hash values.

The best hash table sizes are powers of 2. There is no need to do mod a prime (mod is sooo slow!). If you need less than 32 bits, use a bitmask. For example, if you need only 10 bits, do h = (h & hashmask(10));
In which case, the hash table should have hashsize(10) elements.

If you are hashing n strings (uint8_t **)k, do it like this:

for (i=0, h=0; i<n; ++i) h = hashlittle( k[i], len[i], h);

Note
Made by Bob Jenkins, 2006. bob_j.nosp@m.enki.nosp@m.ns@bu.nosp@m.rtle.nosp@m.burtl.nosp@m.e.ne.nosp@m.t.
Use for hash table lookup, or anything where one collision in 2^^32 is acceptable. Do NOT use for cryptographic purposes.

◆ hashlittle2()

void hashlittle2 ( const void * key,
size_t length,
uint32_t * pc,
uint32_t * pb )
extern

return 2 32-bit hash values

hashlittle2: return 2 32-bit hash values

This is identical to hashlittle(), except it returns two 32-bit hash values instead of just one. This is good enough for hash table lookup with 2^^64 buckets, or if you want a second hash if you're not happy with the first, or if you want a probably-unique 64-bit ID for the key. *pc is better mixed than *pb, so use *pc first. If you want a 64-bit value do something like __"*pc + (((uint64_t)*pb)<<32)"__.

Note
Made by Bob Jenkins, 2006. bob_j.nosp@m.enki.nosp@m.ns@bu.nosp@m.rtle.nosp@m.burtl.nosp@m.e.ne.nosp@m.t.
Use for hash table lookup, or anything where one collision in 2^^32 is acceptable. Do NOT use for cryptographic purposes.

◆ hashbig()

uint32_t hashbig ( const void * key,
size_t length,
uint32_t initval )
extern

hashbig(): This is the same as hashword() on big-endian machines. It is different from hashlittle() on all machines. hashbig() takes advantage of big-endian byte ordering.

Note
Made by Bob Jenkins, 2006. bob_j.nosp@m.enki.nosp@m.ns@bu.nosp@m.rtle.nosp@m.burtl.nosp@m.e.ne.nosp@m.t.
Use for hash table lookup, or anything where one collision in 2^^32 is acceptable. Do NOT use for cryptographic purposes.