Sha256: f5aac7c78732d04d3b439bb1b78cde3b4478383be2fe7c3e5347a0d8a480e38c

Contents?: true

Size: 984 Bytes

Versions: 184

Compression:

Stored size: 984 Bytes

Contents

module SplitIoClient
  module Hashers
    class ImpressionHasher
      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

      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

      private

      def unknown_if_null(value)
        value == nil ? "UNKNOWN" : value
      end

      def zero_if_null(value)
        value == nil ? 0 : value
      end
    end
  end
end

Version data entries

184 entries across 184 versions & 1 rubygems

Version Path
splitclient-rb-7.3.3-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc18-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc18 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc17-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc17 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc16-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc16 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc15-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc15 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc14-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc14 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc13-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc13 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc12-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc12 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc11-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc11 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc10-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-7.3.3.pre.rc10 lib/splitclient-rb/cache/hashers/impression_hasher.rb