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
|
# File 'lib/experiment/evaluation/murmur3.rb', line 15
def hash32x86(input, seed = 0)
data = string_to_utf8_bytes(input)
length = data.length
n_blocks = length >> 2
hash = seed
n_blocks.times do |i|
index = i << 2
k = read_int_le(data, index)
hash = mix32(k, hash)
end
index = n_blocks << 2
k1 = 0
case length - index
when 3
k1 ^= data[index + 2] << 16
k1 ^= data[index + 1] << 8
k1 ^= data[index]
k1 = (k1 * C1_32) & 0xffffffff
k1 = rotate_left(k1, R1_32)
k1 = (k1 * C2_32) & 0xffffffff
hash ^= k1
when 2
k1 ^= data[index + 1] << 8
k1 ^= data[index]
k1 = (k1 * C1_32) & 0xffffffff
k1 = rotate_left(k1, R1_32)
k1 = (k1 * C2_32) & 0xffffffff
hash ^= k1
when 1
k1 ^= data[index]
k1 = (k1 * C1_32) & 0xffffffff
k1 = rotate_left(k1, R1_32)
k1 = (k1 * C2_32) & 0xffffffff
hash ^= k1
end
hash ^= length
fmix32(hash) & 0xffffffff
end
|