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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use platform::*;
use farmhashcc_shared;
use farmhashmk_shared::*;
pub fn mk_hash32_with_seed(s: &[u8], seed: u32) -> u32 {
let len = s.len() as usize;
if len <= 24 {
if len >= 13 {
return mk_hask32_len_13_to_24(s, seed.wrapping_mul(C1))
} else if len >= 5 {
return mk_hash32_len_5_to_12(s, seed)
} else {
return mk_hash32_len_0_to_4(s, seed)
}
}
let h = mk_hask32_len_13_to_24(&s[0 .. 24], seed^(len as u32));
return mur(farmhashcc_shared::hash32(&s[24..])+seed, h)
}
pub fn mk_hash32(mut s: &[u8]) -> u32{
let len = s.len() as usize;
if len <= 24 {
if len <= 12 {
if len <= 4 {
return mk_hash32_len_0_to_4(s, 0)
}
return mk_hash32_len_5_to_12(s, 0)
}
return mk_hask32_len_13_to_24(s, 0)
}
let mut h = len as u32;
let mut g = (len as u32).wrapping_mul(C1);
let mut f: u32 = g;
let a0 = rotate32(fetch32(&s[len-4..]).wrapping_mul(C1), 17).wrapping_mul(C2);
let a1 = rotate32(fetch32(&s[len-8..]).wrapping_mul(C1), 17).wrapping_mul(C2);
let a2 = rotate32(fetch32(&s[len-16..]).wrapping_mul(C1), 17).wrapping_mul(C2);
let a3 = rotate32(fetch32(&s[len-12..]).wrapping_mul(C1), 17).wrapping_mul(C2);
let a4 = rotate32(fetch32(&s[len-20..]).wrapping_mul(C1), 17).wrapping_mul(C2);
h ^= a0;
h = rotate32(h, 19);
h = h.wrapping_mul(5).wrapping_add(0xe6546b64);
h ^= a2;
h = rotate32(h, 19);
h = h.wrapping_mul(5).wrapping_add(0xe6546b64);
g ^= a1;
g = rotate32(g, 19);
g = g.wrapping_mul(5).wrapping_add(0xe6546b64);
g ^= a3;
g = rotate32(g, 19);
g = g.wrapping_mul(5).wrapping_add(0xe6546b64);
f = f.wrapping_add(a4);
f = rotate32(f, 19).wrapping_add(113);
let mut iters = ((len - 1) / 20) as u64;
while iters > 0 {
let a = fetch32(&s);
let b = fetch32(&s[4..]);
let c = fetch32(&s[8..]);
let d = fetch32(&s[12..]);
let e = fetch32(&s[16..]);
h = h.wrapping_add(a);
g = g.wrapping_add(b);
f = f.wrapping_add(c);
h = mur(d, h).wrapping_add(e);
g = mur(c, g).wrapping_add(a);
f = mur(b.wrapping_add(e.wrapping_mul(C1)), f).wrapping_add(d);
f = f.wrapping_add(g);
g = g.wrapping_add(f);
s = &s[20..];
iters-=1;
}
g = rotate32(g, 11).wrapping_mul(C1);
g = rotate32(g, 17).wrapping_mul(C1);
f = rotate32(f, 11).wrapping_mul(C1);
f = rotate32(f, 17).wrapping_mul(C1);
h = rotate32(h.wrapping_add(g), 19);
h = h.wrapping_mul(5).wrapping_add(0xe6546b64);
h = rotate32(h, 17).wrapping_mul(C1);
h = rotate32(h.wrapping_add(f), 19);
h = h.wrapping_mul(5).wrapping_add(0xe6546b64);
h = rotate32(h, 17).wrapping_mul(C1);
return h
}