Class: PEROBS::FNV_Hash_1a_64

Inherits:
Object
  • Object
show all
Defined in:
lib/perobs/FNV_Hash_1a_64.rb

Overview

This is an implementation of the Fowler Noll Vo hashing algorithm in the 1a variant for 64 bit hash values. en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function

Constant Summary collapse

@@OFFSET =
14695981039346656037
@@PRIME =
1099511628211
@@MASK =
2**64 - 1

Class Method Summary collapse

Class Method Details

.digest(item) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/perobs/FNV_Hash_1a_64.rb', line 39

def self.digest(item)
  hash = @@OFFSET

  item.to_s.each_byte do |byte|
    hash ^= byte
    hash *= @@PRIME
    hash &= @@MASK
  end

  hash
end