public interface HashFunction
Hash functions are first initialised with a seed, which may be zero, and then updated with a succession of values that are mixed into the hash state in sequence.
Hash functions may have internal state, but can also be stateless, if their complete state can be represented by the 64-bit intermediate hash state.
incrementalXXH64(),
javaUtilHashing(),
xorShift32()| Modifier and Type | Method and Description |
|---|---|
long |
finalise(long intermediateHash)
Produce a final hash value from the given intermediate hash state.
|
default long |
hashSingleValue(long value)
Produce a 64-bit hash value from a single long value.
|
default int |
hashSingleValueToInt(long value)
Produce a 32-bit hash value from a single long value.
|
static HashFunction |
incrementalXXH64()
Our incremental XXH64 based hash function.
|
long |
initialise(long seed)
Initialise the hash function with the given seed.
|
static HashFunction |
javaUtilHashing()
Same hash function as that used by the standard library hash collections.
|
default int |
toInt(long hash)
Reduce the given 64-bit hash value to a 32-bit value.
|
long |
update(long intermediateHash,
long value)
Update the hash state by mixing the given value into the given intermediate hash state.
|
static HashFunction |
xorShift32()
The default hash function is based on a pseudo-random number generator, which uses the input value as a seed
to the generator.
|
long initialise(long seed)
Different seeds should produce different final hash values.
seed - The initialisation seed for the hash function.long update(long intermediateHash,
long value)
intermediateHash - The intermediate hash state given either by initialise(long), or by a previous
call to this function.value - The value to add to the hash state.long finalise(long intermediateHash)
intermediateHash - the intermediate hash state from which to produce a final hash value.default int toInt(long hash)
hash - The hash value to reduce.default long hashSingleValue(long value)
value - The single value to hash.default int hashSingleValueToInt(long value)
value - The single value to hash.static HashFunction incrementalXXH64()
This hash function is based on xxHash (XXH64 variant), but modified to work incrementally on 8-byte blocks instead of on 32-byte blocks. Basically, the 32-byte block hash loop has been removed, so we use the 8-byte block tail-loop for the entire input.
This hash function is roughly twice as fast as the hash function used for index entries since 2.2.0, about 30% faster than optimised murmurhash3 implementations though not as fast as optimised xxHash implementations due to the smaller block size. It is allocation free, unlike its predecessor. And it retains most of the excellent statistical properties of xxHash, failing only the "TwoBytes" and "Zeroes" keyset tests in SMHasher, passing 12 out of 14 tests. According to Yann Collet on twitter, this modification is expected to mostly cause degraded performance, and worsens some of the avalanche statistics.
This hash function is stateless, so the returned instance can be freely cached and accessed concurrently by multiple threads.
The xxHash algorithm is originally by Yann Collet, and this implementation is with inspiration from Vsevolod Tolstopyatovs implementation in the Zero Allocation Hashing library. Credit for SMHasher goes to Austin Appleby.
static HashFunction javaUtilHashing()
It performs exceptionally poorly for sequences of numbers, as the sequence increments all end up in the same stripe, generating hash values that will end up in the same buckets in collections.
This hash function is stateless, so the returned instance can be freely cached and accessed concurrently by multiple threads.
static HashFunction xorShift32()
This hash function is stateless, so the returned instance can be freely cached and accessed concurrently by multiple threads.
Copyright © 2002–2018 The Neo4j Graph Database Project. All rights reserved.