Module: CityHash
- Defined in:
- lib/cityhash.rb,
lib/cityhash/version.rb,
ext/cityhash/cityhash.cc
Defined Under Namespace
Modules: Internal
Constant Summary collapse
- LOW64_MASK =
0x0000000000000000ffffffffffffffff
- HIGH64_MASK =
0xffffffffffffffff0000000000000000
- VERSION =
"0.7.0"
Class Method Summary collapse
- .hash128(input, seed = nil) ⇒ Object
- .hash32(input) ⇒ Object
- .hash64(input, seed1 = nil, seed2 = nil) ⇒ Object
Class Method Details
.hash128(input, seed = nil) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/cityhash.rb', line 18 def self.hash128(input, seed=nil) if seed seed = [seed & LOW64_MASK, seed & HIGH64_MASK >> 64].pack('QQ') digest = Internal.hash128_with_seed(input, seed) else digest = Internal.hash128(input) end [0..7, 8..15].map { |r| digest[r].unpack('Q').first.to_s }.join.to_i end |
.hash32(input) ⇒ Object
8 9 10 |
# File 'lib/cityhash.rb', line 8 def self.hash32(input) Internal.hash32(input) end |
.hash64(input, seed1 = nil, seed2 = nil) ⇒ Object
12 13 14 15 16 |
# File 'lib/cityhash.rb', line 12 def self.hash64(input, seed1=nil, seed2=nil) return Internal.hash64(input) if seed1.nil? return Internal.hash64_with_seed(input, seed1.to_i) if seed2.nil? Internal.hash64_with_seeds(input, seed1.to_i, seed2.to_i) end |