Class XxHashFunction

java.lang.Object
cloud.opencode.base.hash.function.AbstractHashFunction
cloud.opencode.base.hash.function.XxHashFunction
All Implemented Interfaces:
HashFunction

public final class XxHashFunction extends AbstractHashFunction
xxHash64 hash function implementation xxHash64 哈希函数实现

xxHash is an extremely fast non-cryptographic hash algorithm, working at speeds close to RAM limits.

xxHash 是一种极快的非加密哈希算法,工作速度接近 RAM 限制。

Features | 主要功能:

  • 64-bit output - 64位输出
  • Extremely high performance - 极高性能
  • Good distribution - 良好的分布
  • Configurable seed - 可配置种子

Usage Examples | 使用示例:

HashCode hash = XxHashFunction.xxHash64().hashUtf8("Hello World");
long value = hash.asLong();

Security | 安全性:

  • Thread-safe: Yes - 线程安全: 是
  • Not for cryptographic use - 不用于加密用途

Performance | 性能特性:

  • Time complexity: O(n) where n = input size - O(n), n为输入大小
  • Space complexity: O(1) - O(1)
Since:
JDK 25, opencode-base-hash V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • xxHash64

      public static XxHashFunction xxHash64()
      Creates an xxHash64 function with default seed (0) 使用默认种子(0)创建xxHash64函数
      Returns:
      hash function | 哈希函数
    • xxHash64

      public static XxHashFunction xxHash64(long seed)
      Creates an xxHash64 function with specified seed 使用指定种子创建xxHash64函数
      Parameters:
      seed - seed value | 种子值
      Returns:
      hash function | 哈希函数
    • newHasher

      public Hasher newHasher()
      Description copied from interface: HashFunction
      Creates a new Hasher instance for streaming hash computation 创建新的Hasher实例用于流式哈希计算
      Returns:
      a new Hasher (stateful, not thread-safe) | 新的Hasher(有状态,非线程安全)
    • hashBytes

      public HashCode hashBytes(byte[] input, int offset, int length)
      Description copied from interface: HashFunction
      Computes hash of a byte array portion 计算字节数组部分的哈希
      Parameters:
      input - input bytes | 输入字节
      offset - starting offset | 起始偏移
      length - number of bytes to hash | 要哈希的字节数
      Returns:
      hash code | 哈希码