Module: CityHash

Defined in:
lib/cityhash.rb,
lib/cityhash/version.rb

Defined Under Namespace

Modules: Internal, Version

Class Method Summary collapse

Class Method Details

.hash128(input, seed = []) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/cityhash.rb', line 37

def self.hash128(input, seed = [])
  input_str = input.to_s

  # Ruby 1.8 compatibility
  len = 0
  if input_str.respond_to?(:bytesize)
    len = input_str.bytesize
  else
    len = input_str.size
  end

  if seed.empty?
    return CityHash::Internal.city_hash128(input_str, len).to_i
  end

  return CityHash::Internal.city_hash128_with_seed(input_str, len, seed[0].to_i, seed[1].to_i).to_i
end

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



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/cityhash.rb', line 15

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

  # Ruby 1.8 compatibility
  len = 0
  if input_str.respond_to?(:bytesize)
    len = input_str.bytesize
  else
    len = input_str.size
  end

  if seed1.nil?
    return CityHash::Internal.city_hash64(input_str, len)
  end

  if seed2.nil?
    return CityHash::Internal.city_hash64_with_seed(input_str, len, seed1.to_i)
  end

  return CityHash::Internal.city_hash64_with_seeds(input_str, len, seed1.to_i, seed2.to_i)
end