Class: SplitIoClient::Hashers::ImpressionHasher

Inherits:
Object
  • Object
show all
Defined in:
lib/splitclient-rb/cache/hashers/impression_hasher.rb

Instance Method Summary collapse

Constructor Details

#initializeImpressionHasher

Returns a new instance of ImpressionHasher.



4
5
6
7
8
9
10
11
# File 'lib/splitclient-rb/cache/hashers/impression_hasher.rb', line 4

def initialize
  @murmur_hash_128_64 = case RUBY_PLATFORM
  when 'java' 
    Proc.new { |key, seed| Java::MurmurHash3.hash128x64(key, seed) }
  else
    Proc.new { |key, seed| Digest::MurmurHashMRI3_x64_128.rawdigest(key, [seed].pack('L')) }
  end
end

Instance Method Details

#process(impression) ⇒ Object



13
14
15
16
17
18
19
20
21
# File 'lib/splitclient-rb/cache/hashers/impression_hasher.rb', line 13

def process(impression)
  impression_data = "#{unknown_if_null(impression[:k])}"
  impression_data << ":#{unknown_if_null(impression[:f])}"
  impression_data << ":#{unknown_if_null(impression[:t])}"
  impression_data << ":#{unknown_if_null(impression[:r])}"
  impression_data << ":#{zero_if_null(impression[:c])}"
  
  @murmur_hash_128_64.call(impression_data, 0)[0];
end