blob: 275c8a238232110d792ebe6cb16dd85de6e1ef9a (
plain)
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
|
module fnv1a
const (
fnv64_prime = u64(1099511628211)
fnv64_offset_basis = u64(14695981039346656037)
fnv32_offset_basis = u32(2166136261)
fnv32_prime = u32(16777619)
)
[inline]
pub fn sum32_string(data string) u32 {
mut hash := fnv1a.fnv32_offset_basis
for i in 0 .. data.len {
hash = (hash ^ u32(data[i])) * fnv1a.fnv32_prime
}
return hash
}
[inline]
pub fn sum32(data []byte) u32 {
mut hash := fnv1a.fnv32_offset_basis
for i in 0 .. data.len {
hash = (hash ^ u32(data[i])) * fnv1a.fnv32_prime
}
return hash
}
[inline]
pub fn sum64_string(data string) u64 {
mut hash := fnv1a.fnv64_offset_basis
for i in 0 .. data.len {
hash = (hash ^ u64(data[i])) * fnv1a.fnv64_prime
}
return hash
}
[inline]
pub fn sum64(data []byte) u64 {
mut hash := fnv1a.fnv64_offset_basis
for i in 0 .. data.len {
hash = (hash ^ u64(data[i])) * fnv1a.fnv64_prime
}
return hash
}
|