-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjenkins_hash.h
58 lines (51 loc) · 2.05 KB
/
jenkins_hash.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#ifndef JENKINS_HASH_H_INCLUDED
#define JENKINS_HASH_H_INCLUDED
/* Code from Bob Jenkins, http://burtleburtle.net/bob/hash/index.html */
#include <stdint.h>
#include <stddef.h>
/**
* hashword - hash an array of uint32_t to a single uint32_t value
*
* @k - the key, an array of uint32_t values
* @length - the length of the key, in uint32_ts
* @initval - the previous hash, or an arbitrary value
*/
uint32_t jenkins_hashword(const uint32_t *k, size_t length, uint32_t initval);
/**
* hashword2 - compute two hash values simultaneously
*
* Same as hashword(), but takes two seeds and returns two 32-bit
* values. @pc and @pb must both be nonnull, and *@pc and *@pb must
* both be initialized with seeds.
*
* @k - the key, an array of uint32_t values
* @length - the length of the key, in uint32_ts
* @pc - IN: seed OUT: primary hash value
* @pb - IN: more seed OUT: secondary hash value
*/
void jenkins_hashword2(const uint32_t *k, size_t length, uint32_t *pc, uint32_t *pb);
/**
* hash - 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.
*
*/
uint32_t jenkins_hash(const void *key, size_t length, uint32_t initval);
/**
* hash2 - return two 32-bit hash values
*
* This is identical to hash(), 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)".
*/
void jenkins_hash2(const void *key, size_t length, uint32_t *pc, uint32_t *pb);
#endif /* !JENKINS_HASH_H_INCLUDED */