Module: ConvertSdk::MurmurHash3 Private
- Defined in:
- lib/convert_sdk/murmur_hash3.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Vendored pure-Ruby MurmurHash3 (x86 32-bit variant).
This is the cross-SDK hashing cornerstone: bucketing computes +MurmurHash3.hash(experienceId + visitorId, 9999)+ and MUST produce a byte-identical result to every other Convert SDK (JS, PHP), or a visitor would bucket into a different variation on Ruby than on web. The 75-vector parity suite (+spec/cross_sdk/hash_vectors_spec.rb+) is the proof.
Implemented as pure Ruby with explicit 32-bit masking — no C extension and no gemspec dependency, so it is JRuby-compatible by construction. Ruby integers are arbitrary-precision; the +& MASK_32+ on every arithmetic step is the correctness boundary that emulates 32-bit unsigned overflow.
Reference: Austin Appleby's MurmurHash3_x86_32 (public domain). https://github.com/aappleby/smhasher/blob/master/src/MurmurHash3.cpp
Constant Summary collapse
- MASK_32 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
32-bit overflow mask — applied after every multiply/add/shift.
0xFFFFFFFF- C1 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Canonical MurmurHash3_x86_32 k1-scramble multiply constant.
0xcc9e2d51- C2 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Canonical MurmurHash3_x86_32 k1-scramble second multiply constant.
0x1b873593- M =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Body block mixing multiplier: rotl(h1, R2) * M + N.
5- N =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Body block mixing addend: rotl(h1, R2) * M + N.
0xe6546b64- R1 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
k1 rotate-left amount before the * C2 multiply.
15- R2 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
h1 rotate-left amount in the body mix.
13- FMIX_C1 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Finalization mix (fmix32) first multiply constant.
0x85ebca6b- FMIX_C2 =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Finalization mix (fmix32) second multiply constant.
0xc2b2ae35
Class Method Summary collapse
-
.hash(key, seed) ⇒ Integer
private
Compute the MurmurHash3 x86 32-bit hash of +key+ with +seed+.
Class Method Details
.hash(key, seed) ⇒ Integer
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Compute the MurmurHash3 x86 32-bit hash of +key+ with +seed+.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/convert_sdk/murmur_hash3.rb', line 48 def self.hash(key, seed) data = key.b # raw bytes (ASCII-8BIT view); UTF-8 multi-byte chars hash over their bytes length = data.bytesize h1 = seed & MASK_32 h1 = mix_body(data, length, h1) h1 = mix_tail(data, length, h1) # Finalization: fold in the length, then avalanche. fmix32(h1 ^ length) end |