Class Crc32HashFunction

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

public final class Crc32HashFunction extends AbstractHashFunction
CRC32 hash function implementation CRC32 哈希函数实现

Provides CRC32 and CRC32C (Castagnoli) hash functions using the JDK's built-in implementations.

使用 JDK 内置实现提供 CRC32 和 CRC32C (Castagnoli) 哈希函数。

Features | 主要功能:

  • Standard CRC32 - 标准CRC32
  • CRC32C (Castagnoli) - CRC32C (Castagnoli)
  • Hardware acceleration when available - 硬件加速(可用时)

Usage Examples | 使用示例:

// Standard CRC32
HashCode hash = Crc32HashFunction.crc32().hashBytes(data);

// CRC32C (faster on modern CPUs)
HashCode hashC = Crc32HashFunction.crc32c().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

    • crc32

      public static Crc32HashFunction crc32()
      Creates a standard CRC32 function 创建标准CRC32函数
      Returns:
      hash function | 哈希函数
    • crc32c

      public static Crc32HashFunction crc32c()
      Creates a CRC32C (Castagnoli) function 创建CRC32C (Castagnoli) 函数

      CRC32C is optimized for hardware acceleration on modern CPUs.

      CRC32C 在现代 CPU 上针对硬件加速进行了优化。

      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 | 哈希码