MurmurHash3

An implementation of Austin Appleby's MurmurHash 3 algorithm (MurmurHash3_x86_32). This object contains methods that hash values of various types as well as means to construct Hashing objects.

This algorithm is designed to generate well-distributed non-cryptographic hashes. It is designed to hash data in 32 bit chunks (ints).

The mix method needs to be called at each step to update the intermediate hash value. For the last chunk to incorporate into the hash mixLast may be used instead, which is slightly faster. Finally finalizeHash needs to be called to compute the final hash value.

This is based on the earlier MurmurHash3 code by Rex Kerr, but the MurmurHash3 algorithm was since changed by its creator Austin Appleby to remedy some weaknesses and improve performance. This represents the latest and supposedly final version of the algorithm (revision 136). Even so, test the generated hashes in between Scala versions, even for point releases, as fast, non-cryptographic hashing algorithms evolve rapidly.

See also:
Source:
MurmurHash3.scala
class Object
trait Matchable
class Any

Type members

Classlikes

Value members

Inherited methods

final def arrayHash[@specialized T](a: Array[T], seed: Int): Int

Compute the hash of an array.

Compute the hash of an array. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.

Inherited from:
MurmurHash3
Source:
MurmurHash3.scala
final def bytesHash(data: Array[Byte], seed: Int): Int

Compute the hash of a byte array.

Compute the hash of a byte array. Faster than arrayHash, because it hashes 4 bytes at once. Note that the result is not compatible with arrayHash!

Inherited from:
MurmurHash3
Source:
MurmurHash3.scala
final def finalizeHash(hash: Int, length: Int): Int

Finalize a hash to incorporate the length and make sure all bits avalanche.

Finalize a hash to incorporate the length and make sure all bits avalanche.

Inherited from:
MurmurHash3
Source:
MurmurHash3.scala
final def indexedSeqHash(a: IndexedSeq[Any], seed: Int): Int

Compute the hash of an IndexedSeq.

Compute the hash of an IndexedSeq. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.

Inherited from:
MurmurHash3
Source:
MurmurHash3.scala
final def listHash(xs: List[_], seed: Int): Int

Compute the hash of a List.

Compute the hash of a List. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.

Inherited from:
MurmurHash3
Source:
MurmurHash3.scala
final def mix(hash: Int, data: Int): Int

Mix in a block of data into an intermediate hash value.

Mix in a block of data into an intermediate hash value.

Inherited from:
MurmurHash3
Source:
MurmurHash3.scala
final def mixLast(hash: Int, data: Int): Int

May optionally be used as the last mixing step.

May optionally be used as the last mixing step. Is a little bit faster than mix, as it does no further mixing of the resulting hash. For the last element this is not necessary as the hash is thoroughly mixed during finalization anyway.

Inherited from:
MurmurHash3
Source:
MurmurHash3.scala
final def orderedHash(xs: IterableOnce[Any], seed: Int): Int

Compute a hash that depends on the order of its arguments.

Compute a hash that depends on the order of its arguments. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.

Inherited from:
MurmurHash3
Source:
MurmurHash3.scala
final def productHash(x: Product, seed: Int, ignorePrefix: Boolean): Int

Compute the hash of a product

Compute the hash of a product

Inherited from:
MurmurHash3
Source:
MurmurHash3.scala
final def rangeHash(start: Int, step: Int, last: Int, seed: Int): Int

Compute the hash of a Range with at least 2 elements.

Compute the hash of a Range with at least 2 elements. Ranges with fewer elements need to use seqHash instead. The last parameter must be the actual last element produced by a Range, not the nominal end.

Inherited from:
MurmurHash3
Source:
MurmurHash3.scala
final def stringHash(str: String, seed: Int): Int

Compute the hash of a string

Compute the hash of a string

Inherited from:
MurmurHash3
Source:
MurmurHash3.scala
final def unorderedHash(xs: IterableOnce[Any], seed: Int): Int

Compute a hash that is symmetric in its arguments - that is a hash where the order of appearance of elements does not matter.

Compute a hash that is symmetric in its arguments - that is a hash where the order of appearance of elements does not matter. This is useful for hashing sets, for example.

Inherited from:
MurmurHash3
Source:
MurmurHash3.scala

Concrete fields

final val arraySeed: 1007110753
final val mapSeed: Int
final val productSeed: -889275714
final val seqSeed: Int
final val setSeed: Int
final val stringSeed: -137723950
final val symmetricSeed: -1248659538
final val traversableSeed: -415593707