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-8.1.2.pre.rc1-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.1.2.pre.rc1 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.1.1-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.1.1 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.1.1.pre.rc3-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.1.1.pre.rc3 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.1.1.pre.rc2-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.1.1.pre.rc2 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.1.1.pre.rc1-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.1.1.pre.rc1 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.1.0-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.1.0 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.1.0.pre.rc1-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.1.0.pre.rc1 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.0.1-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.0.1 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.0.1.pre.rc1-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.0.1.pre.rc1 lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.0.0-java lib/splitclient-rb/cache/hashers/impression_hasher.rb
splitclient-rb-8.0.0 lib/splitclient-rb/cache/hashers/impression_hasher.rb