LiveStyle.Hash.Murmur (LiveStyle v0.13.0)
View SourceMurmurHash2 32-bit implementation for LiveStyle.
This is a port of the JavaScript MurmurHash2 implementation used by StyleX. The algorithm produces stable, well-distributed 32-bit hashes suitable for generating short, unique class names.
Algorithm
MurmurHash2 is a non-cryptographic hash function designed for speed. It processes input in 4-byte chunks and produces a 32-bit hash.
JavaScript Compatibility
This implementation carefully matches JavaScript's bitwise semantics:
- 32-bit signed integer conversions (like
|0) - Unsigned right shift (
>>>) - Multiplication with implicit truncation
Example
iex> LiveStyle.Hash.Murmur.hash("hello", 1)
613153351
Summary
Functions
Computes the MurmurHash2 32-bit hash of a string.
Functions
@spec hash(String.t(), non_neg_integer()) :: non_neg_integer()
Computes the MurmurHash2 32-bit hash of a string.
Parameters
str- The string to hashseed- The seed value (default: 0)
Returns
A 32-bit unsigned integer hash value.
Examples
iex> LiveStyle.Hash.Murmur.hash("hello")
1335831723
iex> LiveStyle.Hash.Murmur.hash("hello", 1)
613153351