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.
Attributes
- See also
- Source
- MurmurHash3.scala
- Graph
-
- Supertypes
- Self type
-
MurmurHash3.type
Members list
Type members
Classlikes
Attributes
- Source
- MurmurHash3.scala
- Supertypes
Value members
Concrete methods
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Computes the hashCode of a case class instance. This method returns the same value as x.hashCode if x is an instance of a case class with the default, synthetic hashCode.
Computes the hashCode of a case class instance. This method returns the same value as x.hashCode if x is an instance of a case class with the default, synthetic hashCode.
This method can be used to implement case classes with a cached hashCode:
case class C(data: Data) {
override lazy val hashCode: Int = MurmurHash3.caseClassHash(this)
}
NOTE: For case classes (or subclasses) that override productPrefix, the caseClassName parameter needs to be specified in order to obtain the same result as the synthetic hashCode. Otherwise, the value is not in sync with the case class equals method (scala/bug#13033).
scala> case class C(x: Int) { override def productPrefix = "Y" }
scala> C(1).hashCode
val res0: Int = -668012062
scala> MurmurHash3.caseClassHash(C(1))
val res1: Int = 1015658380
scala> MurmurHash3.caseClassHash(C(1), "C")
val res2: Int = -668012062
Value parameters
- caseClassName
-
the case class name to use for hashing, or
nullto usex.productPrefix - x
-
the case class instance to hash
Attributes
- Returns
-
the hash code, equivalent to the synthetic
hashCodewhencaseClassNamematches the declared class name - Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
To offer some potential for optimization.
To offer some potential for optimization.
Value parameters
- xs
-
the sequence to hash (dispatches to specialized implementations for
IndexedSeqandList)
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Deprecated methods
Attributes
- Deprecated
-
[Since version 2.13.17]use `caseClassHash` instead - Source
- MurmurHash3.scala
Attributes
- Deprecated
-
[Since version 2.13.17]use `caseClassHashing` instead - Source
- MurmurHash3.scala
Inherited methods
Computes the hash of an array. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Computes the hash of an array. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Value parameters
- a
-
the array to hash
- seed
-
the initial seed for the hash computation
Attributes
- Inherited from:
- MurmurHash3 (hidden)
- Source
- MurmurHash3.scala
Computes 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!
Computes 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!
Value parameters
- data
-
the byte array to hash
- seed
-
the initial seed for the hash computation
Attributes
- Inherited from:
- MurmurHash3 (hidden)
- Source
- MurmurHash3.scala
See the MurmurHash3.caseClassHash(x:Product,caseClassName:String) overload.
See the MurmurHash3.caseClassHash(x:Product,caseClassName:String) overload.
Value parameters
- caseClassName
-
the case class name used for hashing, or
nullto fall back tox.productPrefix - seed
-
the initial seed for the hash computation
- x
-
the case class instance to hash
Attributes
- Inherited from:
- MurmurHash3 (hidden)
- Source
- MurmurHash3.scala
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.
Value parameters
- hash
-
the intermediate hash value after all mix steps
- length
-
the number of elements hashed
Attributes
- Inherited from:
- MurmurHash3 (hidden)
- Source
- MurmurHash3.scala
Computes the hash of an IndexedSeq. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Computes the hash of an IndexedSeq. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Value parameters
- a
-
the indexed sequence to hash
- seed
-
the initial seed for the hash computation
Attributes
- Inherited from:
- MurmurHash3 (hidden)
- Source
- MurmurHash3.scala
Computes the hash of a List. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Computes the hash of a List. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Value parameters
- seed
-
the initial seed for the hash computation
- xs
-
the list to hash
Attributes
- Inherited from:
- MurmurHash3 (hidden)
- Source
- MurmurHash3.scala
Mix in a block of data into an intermediate hash value.
Mix in a block of data into an intermediate hash value.
Value parameters
- data
-
the new block of data to mix in
- hash
-
the intermediate hash value
Attributes
- Inherited from:
- MurmurHash3 (hidden)
- Source
- MurmurHash3.scala
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.
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.
Value parameters
- data
-
the last block of data to mix in
- hash
-
the intermediate hash value
Attributes
- Inherited from:
- MurmurHash3 (hidden)
- Source
- MurmurHash3.scala
Computes a hash that depends on the order of its arguments. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Computes a hash that depends on the order of its arguments. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Value parameters
- seed
-
the initial seed for the hash computation
- xs
-
the elements to hash in traversal order
Attributes
- Inherited from:
- MurmurHash3 (hidden)
- Source
- MurmurHash3.scala
Attributes
- Inherited from:
- MurmurHash3 (hidden)
- Source
- MurmurHash3.scala
Computes 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.
Computes 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.
Value parameters
- last
-
the actual last element produced by the range
- seed
-
the initial seed for the hash computation
- start
-
the first element of the range
- step
-
the increment between successive elements
Attributes
- Inherited from:
- MurmurHash3 (hidden)
- Source
- MurmurHash3.scala
Computes the hash of a string.
Computes the hash of a string.
Value parameters
- seed
-
the initial seed for the hash computation
- str
-
the string to hash
Attributes
- Inherited from:
- MurmurHash3 (hidden)
- Source
- MurmurHash3.scala
Computes 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.
Computes 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.
Value parameters
- seed
-
the initial seed for the hash computation
- xs
-
the elements to hash (order-independent)
Attributes
- Inherited from:
- MurmurHash3 (hidden)
- Source
- MurmurHash3.scala
Concrete fields
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala
Attributes
- Source
- MurmurHash3.scala