Class MurmurHash

java.lang.Object
org.miaixz.bus.core.codec.hash.MurmurHash
All Implemented Interfaces:
Encoder<byte[],Number>, Hash128<byte[]>, Hash32<byte[]>, Hash64<byte[]>

public class MurmurHash extends Object implements Hash32<byte[]>, Hash64<byte[]>, Hash128<byte[]>
Murmur3 32bit、64bit、128bit 哈希算法实现 此算法来自于:...

32-bit Java port of https://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp#94 128-bit Java port of https://code.google.com/p/smhasher/source/browse/trunk/MurmurHash3.cpp#255

Since:
Java 17+
Author:
Kimi Liu
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final MurmurHash
    单例
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    encode(byte[] bytes)
    执行编码
    hash128(byte[] data)
    Murmur3 128-bit 算法.
    hash128(byte[] data, int length, int seed)
    Murmur3 128-bit variant.
    hash128(byte[] data, int offset, int length, int seed)
    Murmur3 128-bit variant.
    Murmur3 128-bit Hash值计算
    int
    hash32(byte[] data)
    Murmur3 32-bit Hash值计算
    int
    hash32(byte[] data, int length, int seed)
    Murmur3 32-bit Hash值计算
    int
    hash32(byte[] data, int offset, int length, int seed)
    Murmur3 32-bit Hash值计算
    int
    Murmur3 32-bit Hash值计算
    long
    hash64(byte[] data)
    Murmur3 64-bit 算法 This is essentially MSB 8 bytes of Murmur3 128-bit variant.
    long
    hash64(byte[] data, int length, int seed)
    类Murmur3 64-bit 算法 This is essentially MSB 8 bytes of Murmur3 128-bit variant.
    long
    Murmur3 64-bit Hash值计算

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • INSTANCE

      public static final MurmurHash INSTANCE
      单例
  • Constructor Details

    • MurmurHash

      public MurmurHash()
  • Method Details

    • encode

      public Number encode(byte[] bytes)
      Description copied from interface: Encoder
      执行编码
      Specified by:
      encode in interface Encoder<byte[],Number>
      Specified by:
      encode in interface Hash128<byte[]>
      Specified by:
      encode in interface Hash32<byte[]>
      Specified by:
      encode in interface Hash64<byte[]>
      Parameters:
      bytes - 被编码的数据
      Returns:
      编码后的数据
    • hash32

      public int hash32(CharSequence data)
      Murmur3 32-bit Hash值计算
      Parameters:
      data - 数据
      Returns:
      Hash值
    • hash32

      public int hash32(byte[] data)
      Murmur3 32-bit Hash值计算
      Specified by:
      hash32 in interface Hash32<byte[]>
      Parameters:
      data - 数据
      Returns:
      Hash值
    • hash32

      public int hash32(byte[] data, int length, int seed)
      Murmur3 32-bit Hash值计算
      Parameters:
      data - 数据
      length - 长度
      seed - 种子,默认0
      Returns:
      Hash值
    • hash32

      public int hash32(byte[] data, int offset, int length, int seed)
      Murmur3 32-bit Hash值计算
      Parameters:
      data - 数据
      offset - 数据开始位置
      length - 长度
      seed - 种子,默认0
      Returns:
      Hash值
    • hash64

      public long hash64(CharSequence data)
      Murmur3 64-bit Hash值计算
      Parameters:
      data - 数据
      Returns:
      Hash值
    • hash64

      public long hash64(byte[] data)
      Murmur3 64-bit 算法 This is essentially MSB 8 bytes of Murmur3 128-bit variant.
      Specified by:
      hash64 in interface Hash64<byte[]>
      Parameters:
      data - 数据
      Returns:
      Hash值
    • hash64

      public long hash64(byte[] data, int length, int seed)
      类Murmur3 64-bit 算法 This is essentially MSB 8 bytes of Murmur3 128-bit variant.
      Parameters:
      data - 数据
      length - 长度
      seed - 种子,默认0
      Returns:
      Hash值
    • hash128

      public No128 hash128(CharSequence data)
      Murmur3 128-bit Hash值计算
      Parameters:
      data - 数据
      Returns:
      Hash值 (2 longs)
    • hash128

      public No128 hash128(byte[] data)
      Murmur3 128-bit 算法.
      Specified by:
      hash128 in interface Hash128<byte[]>
      Parameters:
      data - -数据
      Returns:
      Hash值 (2 longs)
    • hash128

      public No128 hash128(byte[] data, int length, int seed)
      Murmur3 128-bit variant.
      Parameters:
      data - 数据
      length - 长度
      seed - 种子,默认0
      Returns:
      Hash值(2 longs)
    • hash128

      public No128 hash128(byte[] data, int offset, int length, int seed)
      Murmur3 128-bit variant.
      Parameters:
      data - 数据
      offset - 数据开始位置
      length - 长度
      seed - 种子,默认0
      Returns:
      Hash值(2 longs)