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
- Graph
-
- Supertypes
- Self type
-
MurmurHash3.type
Members list
Type members
Classlikes
Attributes
- Supertypes
Value members
Concrete methods
Compute 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.
Compute 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
Attributes
To offer some potential for optimization.
To offer some potential for optimization.
Attributes
Deprecated methods
Attributes
- Deprecated
-
[Since version 2.13.17]use `caseClassHash` instead
Attributes
- Deprecated
-
[Since version 2.13.17]use `caseClassHashing` instead
Inherited methods
Compute the hash of an array. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Compute the hash of an array. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Attributes
- Inherited from:
- MurmurHash3 (hidden)
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!
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!
Attributes
- Inherited from:
- MurmurHash3 (hidden)
See the MurmurHash3.caseClassHash overload
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.
Attributes
- Inherited from:
- MurmurHash3 (hidden)
Compute the hash of an IndexedSeq. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Compute the hash of an IndexedSeq. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Attributes
- Inherited from:
- MurmurHash3 (hidden)
Compute the hash of a List. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Compute the hash of a List. Potential range hashes are recognized to produce a hash that is compatible with rangeHash.
Attributes
- Inherited from:
- MurmurHash3 (hidden)
Mix in a block of data into an intermediate hash value.
Mix in a block of data into an intermediate hash value.
Attributes
- Inherited from:
- MurmurHash3 (hidden)
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.
Attributes
- Inherited from:
- MurmurHash3 (hidden)
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.
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.
Attributes
- Inherited from:
- MurmurHash3 (hidden)
Attributes
- Inherited from:
- MurmurHash3 (hidden)
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.
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.
Attributes
- Inherited from:
- MurmurHash3 (hidden)
Compute the hash of a string
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.
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.
Attributes
- Inherited from:
- MurmurHash3 (hidden)