Class Adler32HashFunction

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

public final class Adler32HashFunction extends AbstractHashFunction
Adler-32 hash function implementation Adler-32 哈希函数实现

Wraps Adler32 to provide a 32-bit checksum hash function. Adler-32 is faster than CRC32 but slightly less reliable for error detection.

封装 Adler32,提供32位校验和哈希函数。 Adler-32 比 CRC32 更快,但在错误检测方面稍微不太可靠。

Features | 主要功能:

  • 32-bit checksum output - 32位校验和输出
  • Fast computation - 快速计算
  • Streaming hash via Hasher - 通过Hasher的流式哈希

Usage Examples | 使用示例:

HashCode hash = Adler32HashFunction.adler32().hashBytes(data);
int checksum = hash.asInt();

// Streaming via Hasher
Hasher hasher = Adler32HashFunction.adler32().newHasher();
hasher.putUtf8("Hello").putInt(42);
HashCode streamHash = hasher.hash();

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.3
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • adler32

      public static Adler32HashFunction adler32()
      Creates an Adler-32 hash function 创建 Adler-32 哈希函数
      Returns:
      Adler-32 hash function | Adler-32 哈希函数
    • 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 | 哈希码