Class CityHash

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

public class CityHash extends Object implements Hash32<byte[]>, Hash64<byte[]>, Hash128<byte[]>
Google发布的Hash计算算法:CityHash64 与 CityHash128。 它们分别根据字串计算 64 和 128 位的散列值。这些算法不适用于加密,但适合用在散列表等处。

代码来自:https://github.com/rolandhe/string-tools 原始算法:https://github.com/google/cityhash

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

    • INSTANCE

      public static CityHash INSTANCE
      单例
  • Constructor Details

    • CityHash

      public CityHash()
  • 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(byte[] data)
      计算32位City Hash值
      Specified by:
      hash32 in interface Hash32<byte[]>
      Parameters:
      data - 数据
      Returns:
      hash值
    • hash64

      public long hash64(byte[] data)
      计算64位City Hash值
      Specified by:
      hash64 in interface Hash64<byte[]>
      Parameters:
      data - 数据
      Returns:
      hash值
    • hash64

      public long hash64(byte[] data, long seed0, long seed1)
      计算64位City Hash值
      Parameters:
      data - 数据
      seed0 - 种子1
      seed1 - 种子2
      Returns:
      hash值
    • hash64

      public long hash64(byte[] data, long seed)
      计算64位City Hash值,种子1使用默认的k2
      Parameters:
      data - 数据
      seed - 种子2
      Returns:
      hash值
    • hash128

      public No128 hash128(byte[] data)
      计算128位City Hash值
      Specified by:
      hash128 in interface Hash128<byte[]>
      Parameters:
      data - 数据
      Returns:
      hash值
    • hash128

      public No128 hash128(byte[] data, No128 seed)
      计算128位City Hash值
      Parameters:
      data - 数据
      seed - 种子
      Returns:
      hash值