-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhashes.c
46 lines (32 loc) · 803 Bytes
/
hashes.c
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
/*
* Author: Chris Wailes <[email protected]>
* Project: Chris's Awesome Standard Library
* Description: Simple, non-cryptographically secure, hashes.
*/
// Standard Includes
#include <sys/types.h>
// Project Includes
// Macros
// Global Variables
// Functions
uint bernstein_hash(const unsigned char* data, uint length) {
uint hash = 0;
while (length-- > 0) {
hash = 33 * hash + *data++;
}
return hash;
}
uint sax_hash(const unsigned char* data, uint length) {
uint hash = 0;
while (length-- > 0) {
hash ^= (hash << 5) + (hash >> 2) + (unsigned char)*data++;
}
return hash;
}
uint sdbm_hash(const unsigned char* data, uint length) {
uint hash = 0;
while (length-- > 0) {
hash = (unsigned char)*data++ + (hash << 6) + (hash << 16) - hash;
}
return hash;
}