Class: Bloombroom::FNVB

Inherits:
Object
  • Object
show all
Defined in:
lib/bloombroom/hash/fnv_b.rb

Constant Summary collapse

INIT32 =
0x811c9dc5
INIT64 =
0xcbf29ce484222325
PRIME32 =
0x01000193
PRIME64 =
0x100000001b3
MOD32 =
2 ** 32
MOD64 =
2 ** 64

Class Method Summary collapse

Class Method Details

.fnv1_32(data) ⇒ Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/bloombroom/hash/fnv_b.rb', line 12

def self.fnv1_32(data)
  hash = INIT32

  data.each_byte do |byte|
    hash = (hash * PRIME32) % MOD32
    hash = hash ^ byte
  end

  hash
end

.fnv1_64(data) ⇒ Object



23
24
25
26
27
28
29
30
31
32
# File 'lib/bloombroom/hash/fnv_b.rb', line 23

def self.fnv1_64(data)
  hash = INIT64

  data.each_byte do |byte|
    hash = (hash * PRIME64) % MOD64
    hash = hash ^ byte
  end

  hash
end

.fnv1a_32(data) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/bloombroom/hash/fnv_b.rb', line 34

def self.fnv1a_32(data)
  hash = INIT32

  data.each_byte do |byte|
    hash = hash ^ byte
    hash = (hash * PRIME32) % MOD32
  end

  hash
end

.fnv1a_64(data) ⇒ Object



45
46
47
48
49
50
51
52
53
54
# File 'lib/bloombroom/hash/fnv_b.rb', line 45

def self.fnv1a_64(data)
  hash = INIT64

  data.each_byte do |byte|
    hash = hash ^ byte
    hash = (hash * PRIME64) % MOD64
  end

  hash
end