Class Fnv1aHashFunction

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

public final class Fnv1aHashFunction extends AbstractHashFunction
FNV-1a hash function implementation FNV-1a 哈希函数实现

Fowler-Noll-Vo (FNV) hash is a non-cryptographic hash function with good distribution characteristics. FNV-1a is a variant that XORs the input byte before multiplying.

Fowler-Noll-Vo (FNV) 哈希是一种具有良好分布特性的非加密哈希函数。 FNV-1a 是一种在乘法之前对输入字节进行 XOR 的变体。

Features | 主要功能:

  • 32-bit and 64-bit variants - 32位和64位变体
  • Simple and fast implementation - 简单快速的实现
  • Good distribution - 良好的分布

Usage Examples | 使用示例:

HashCode hash32 = Fnv1aHashFunction.fnv1a_32().hashUtf8("Hello");
HashCode hash64 = Fnv1aHashFunction.fnv1a_64().hashBytes(data);

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

    • fnv1a_32

      public static Fnv1aHashFunction fnv1a_32()
      Creates a 32-bit FNV-1a function 创建32位FNV-1a函数
      Returns:
      hash function | 哈希函数
    • fnv1a_64

      public static Fnv1aHashFunction fnv1a_64()
      Creates a 64-bit FNV-1a function 创建64位FNV-1a函数
      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 | 哈希码