Package org.apache.pekko.routing
Class MurmurHash
java.lang.Object
org.apache.pekko.routing.MurmurHash
An object designed to generate well-distributed non-cryptographic
hashes. It is designed to hash a collection of integers; along with
the integers to hash, it generates two magic streams of integers to
increase the distribution of repetitive input sequences. Thus,
three methods need to be called at each step (to start and to
incorporate a new integer) to update the values. Only one method
needs to be called to finalize the hash.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> intCompute a high-quality hash of an arraystatic intextendHash(int hash, int value, int magicA, int magicB) Incorporates a new value into an existing hash.static intfinalizeHash(int hash) Once all hashes have been incorporated, this performs a final mixingstatic intnextMagicA(int magicA) Given a magic integer from the first stream, compute the nextstatic intnextMagicB(int magicB) Given a magic integer from the second stream, compute the nextstatic intstartHash(int seed) Begin a new hash with a seed value.static intThe initial magic integers in the first stream.static intThe initial magic integer in the second stream.static intstringHash(String s) Compute a high-quality hash of a stringstatic <T> intsymmetricHash(scala.collection.IterableOnce<T> xs, int seed) Compute a hash that is symmetric in its arguments--that is, where the order of appearance of elements does not matter.
-
Constructor Details
-
MurmurHash
public MurmurHash()
-
-
Method Details
-
startHash
public static int startHash(int seed) Begin a new hash with a seed value. -
startMagicA
public static int startMagicA()The initial magic integers in the first stream. -
startMagicB
public static int startMagicB()The initial magic integer in the second stream. -
extendHash
public static int extendHash(int hash, int value, int magicA, int magicB) Incorporates a new value into an existing hash.- Parameters:
hash- the prior hash valuevalue- the new value to incorporatemagicA- a magic integer from the streammagicB- a magic integer from a different stream- Returns:
- the updated hash value
-
nextMagicA
public static int nextMagicA(int magicA) Given a magic integer from the first stream, compute the next -
nextMagicB
public static int nextMagicB(int magicB) Given a magic integer from the second stream, compute the next -
finalizeHash
public static int finalizeHash(int hash) Once all hashes have been incorporated, this performs a final mixing -
arrayHash
Compute a high-quality hash of an array -
stringHash
Compute a high-quality hash of a string -
symmetricHash
public static <T> int symmetricHash(scala.collection.IterableOnce<T> xs, int seed) Compute a hash that is symmetric in its arguments--that is, where the order of appearance of elements does not matter. This is useful for hashing sets, for example.
-