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.8.1"

Class Method Summary collapse

Class Method Details

.hash128(input, seed = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/cityhash.rb', line 22

def self.hash128(input, seed=nil)
  input = input.to_s

  digest = if seed
    Internal.hash128_with_seed(input, packed_seed(seed))
  else
    Internal.hash128(input)
  end

  unpacked_digest(digest)
end

.hash128crc(input, seed = nil) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
# File 'lib/cityhash.rb', line 34

def self.hash128crc(input, seed=nil)
  input = input.to_s

  digest = if seed
    Internal.hash128crc_with_seed(input, packed_seed(seed))
  else
    Internal.hash128crc(input)
  end

  unpacked_digest(digest)
end

.hash256crc(input) ⇒ Object



46
47
48
49
50
51
# File 'lib/cityhash.rb', line 46

def self.hash256crc(input)
  input = input.to_s
  digest = Internal.hash256crc(input)

  [0..7, 8..15, 16..23].map { |r| digest[r].unpack('Q').first.to_s }.join.to_i
end

.hash32(input) ⇒ Object



8
9
10
11
12
# File 'lib/cityhash.rb', line 8

def self.hash32(input)
  input = input.to_s

  Internal.hash32(input)
end

.hash64(input, seed1 = nil, seed2 = nil) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/cityhash.rb', line 14

def self.hash64(input, seed1=nil, seed2=nil)
  input = input.to_s

  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