Class MurmurHasher

java.lang.Object
org.apache.arrow.memory.util.hash.MurmurHasher
All Implemented Interfaces:
ArrowBufHasher

public class MurmurHasher extends Object implements ArrowBufHasher
Implementation of the Murmur hashing algorithm. Details of the algorithm can be found in https://en.wikipedia.org/wiki/MurmurHash

Murmur hashing is computationally expensive, as it involves several integer multiplications. However, the produced hash codes have good quality in the sense that they are uniformly distributed in the universe.

Therefore, this algorithm is suitable for scenarios where uniform hashing is desired (e.g. in an open addressing hash table/hash set).

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a default Murmur hasher, with seed 0.
    MurmurHasher(int seed)
    Creates a Murmur hasher.
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    combineHashCode(int currentHashCode, int intValue)
    Combine the current hash code and a new int value to calculate a new hash code.
    boolean
    equals(@Nullable Object o)
     
    static int
    finalizeHashCode(int hashCode, long length)
    Finalizing the hash code.
    int
     
    int
    hashCode(long address, long length)
    Calculates the hash code for a memory region.
    static int
    hashCode(long address, long length, int seed)
    Calculates the hash code for a memory region.
    int
    hashCode(ArrowBuf buf, long offset, long length)
    Calculates the hash code for a memory region.
    static int
    hashCode(ArrowBuf buf, long offset, long length, int seed)
    Calculates the hash code for a memory region.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MurmurHasher

      public MurmurHasher()
      Creates a default Murmur hasher, with seed 0.
    • MurmurHasher

      public MurmurHasher(int seed)
      Creates a Murmur hasher.
      Parameters:
      seed - the seed for the hasher.
  • Method Details

    • hashCode

      public int hashCode(long address, long length)
      Description copied from interface: ArrowBufHasher
      Calculates the hash code for a memory region.
      Specified by:
      hashCode in interface ArrowBufHasher
      Parameters:
      address - start address of the memory region.
      length - length of the memory region.
      Returns:
      the hash code.
    • hashCode

      public int hashCode(ArrowBuf buf, long offset, long length)
      Description copied from interface: ArrowBufHasher
      Calculates the hash code for a memory region.
      Specified by:
      hashCode in interface ArrowBufHasher
      Parameters:
      buf - the buffer for the memory region.
      offset - offset within the buffer for the memory region.
      length - length of the memory region.
      Returns:
      the hash code.
    • hashCode

      public static int hashCode(ArrowBuf buf, long offset, long length, int seed)
      Calculates the hash code for a memory region.
      Parameters:
      buf - the buffer for the memory region.
      offset - offset within the buffer for the memory region.
      length - length of the memory region.
      seed - the seed.
      Returns:
      the hash code.
    • hashCode

      public static int hashCode(long address, long length, int seed)
      Calculates the hash code for a memory region.
      Parameters:
      address - start address of the memory region.
      length - length of the memory region.
      seed - the seed.
      Returns:
      the hash code.
    • combineHashCode

      public static int combineHashCode(int currentHashCode, int intValue)
      Combine the current hash code and a new int value to calculate a new hash code.
      Parameters:
      currentHashCode - the current hash code.
      intValue - the new int value.
      Returns:
      the new hah code.
    • finalizeHashCode

      public static int finalizeHashCode(int hashCode, long length)
      Finalizing the hash code.
      Parameters:
      hashCode - the current hash code.
      length - the length of the memory region.
      Returns:
      the finalized hash code.
    • equals

      public boolean equals(@Nullable Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object