java.lang.Object
org.elasticsearch.common.hash.Murmur3Hasher
org.elasticsearch.common.hash.BufferedMurmur3Hasher
A buffered Murmur3 hasher that allows hashing strings and longs efficiently.
It uses a byte array buffer to reduce allocations for converting strings and longs to bytes before passing them to the hasher.
The buffer also allows for more efficient execution by minimizing the number of times the underlying hasher is updated,
and by maximizing the amount of data processed in each update call.
-
Field Summary
FieldsFields inherited from class org.elasticsearch.common.hash.Murmur3Hasher
METHOD -
Constructor Summary
ConstructorsConstructorDescriptionBufferedMurmur3Hasher(long seed) BufferedMurmur3Hasher(long seed, int bufferSize) Constructs a BufferedMurmur3Hasher with a specified seed and buffer size. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddLong(long value) Adds a long value to the hasher.voidaddLongs(long v1, long v2) Adds two long values to the hasher.voidaddLongs(long v1, long v2, long v3, long v4) Adds four long values to the hasher.voidAdds a string to the hasher.Completes the hash of all bytes previously passed toMurmur3Hasher.update(byte[]).voidreset()Clears all bytes previously passed toMurmur3Hasher.update(byte[])and prepares for the calculation of a new hash.Methods inherited from class org.elasticsearch.common.hash.Murmur3Hasher
digest, digestHash, getAlgorithm, update, update
-
Field Details
-
DEFAULT_BUFFER_SIZE
public static final int DEFAULT_BUFFER_SIZE- See Also:
-
-
Constructor Details
-
BufferedMurmur3Hasher
public BufferedMurmur3Hasher(long seed) -
BufferedMurmur3Hasher
public BufferedMurmur3Hasher(long seed, int bufferSize) Constructs a BufferedMurmur3Hasher with a specified seed and buffer size.- Parameters:
seed- the seed for the Murmur3 hash functionbufferSize- the size of the buffer in bytes, must be at least 32
-
-
Method Details
-
digestHash
Description copied from class:Murmur3HasherCompletes the hash of all bytes previously passed toMurmur3Hasher.update(byte[]). Allows passing in a re-usableMurmurHash3.Hash128instance to avoid allocations.- Overrides:
digestHashin classMurmur3Hasher
-
reset
public void reset()Description copied from class:Murmur3HasherClears all bytes previously passed toMurmur3Hasher.update(byte[])and prepares for the calculation of a new hash.- Overrides:
resetin classMurmur3Hasher
-
addString
Adds a string to the hasher. The string is converted to UTF-8 and written into the buffer. The buffer is resized if necessary to accommodate the UTF-8 encoded string.- Parameters:
value- the string value to add
-
addLong
public void addLong(long value) Adds a long value to the hasher. The long is written in little-endian format.- Parameters:
value- the long value to add
-
addLongs
public void addLongs(long v1, long v2) Adds two long values to the hasher. Each long is written in little-endian format.- Parameters:
v1- the first long value to addv2- the second long value to add
-
addLongs
public void addLongs(long v1, long v2, long v3, long v4) Adds four long values to the hasher. Each long is written in little-endian format.- Parameters:
v1- the first long value to addv2- the second long value to addv3- the third long value to addv4- the fourth long value to add
-