Class BufferedMurmur3Hasher

java.lang.Object
org.elasticsearch.common.hash.Murmur3Hasher
org.elasticsearch.common.hash.BufferedMurmur3Hasher

public class BufferedMurmur3Hasher extends Murmur3Hasher
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 Details

  • 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 function
      bufferSize - the size of the buffer in bytes, must be at least 32
  • Method Details

    • digestHash

      public MurmurHash3.Hash128 digestHash(MurmurHash3.Hash128 hash)
      Description copied from class: Murmur3Hasher
      Completes the hash of all bytes previously passed to Murmur3Hasher.update(byte[]). Allows passing in a re-usable MurmurHash3.Hash128 instance to avoid allocations.
      Overrides:
      digestHash in class Murmur3Hasher
    • reset

      public void reset()
      Description copied from class: Murmur3Hasher
      Clears all bytes previously passed to Murmur3Hasher.update(byte[]) and prepares for the calculation of a new hash.
      Overrides:
      reset in class Murmur3Hasher
    • addString

      public void addString(String value)
      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 add
      v2 - 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 add
      v2 - the second long value to add
      v3 - the third long value to add
      v4 - the fourth long value to add