Class AbstractHashFunction
java.lang.Object
cloud.opencode.base.hash.function.AbstractHashFunction
- All Implemented Interfaces:
HashFunction
- Direct Known Subclasses:
Adler32HashFunction, Crc32HashFunction, Fnv1aHashFunction, HmacHashFunction, MessageDigestHashFunction, Murmur3HashFunction, SipHashFunction, XxHashFunction
Abstract base class for hash functions
哈希函数抽象基类
Provides common implementations for hash function methods, reducing code duplication in concrete implementations.
提供哈希函数方法的通用实现,减少具体实现中的代码重复。
Features | 主要功能:
- Default method implementations - 默认方法实现
- AbstractHasher base class - AbstractHasher基类
- Common utility methods - 通用工具方法
Usage Examples | 使用示例:
// Extend to create custom hash functions
// 扩展以创建自定义哈希函数
public class MyHash extends AbstractHashFunction {
@Override
public HashCode hash(byte[] data) {
// custom hashing logic
}
}
Security | 安全性:
- Thread-safe: Implementation-dependent - 线程安全: 取决于实现
- Null-safe: No - 空值安全: 否
Performance | 性能特性:
- Time complexity: O(n) where n = input size - O(n), n为输入大小
- Space complexity: O(1) for hash state - 哈希状态 O(1)
- Since:
- JDK 25, opencode-base-hash V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static classAbstract base class for Hasher implementations Hasher实现的抽象基类protected static classBuffer-based hasher for accumulating bytes 基于缓冲区的hasher用于累积字节 -
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractHashFunction(int bits, String name) Creates an abstract hash function 创建抽象哈希函数 -
Method Summary
Modifier and TypeMethodDescriptionintbits()Gets the number of bits in the hash output 获取哈希输出的位数hashBytes(byte[] input) Computes hash of a byte array 计算字节数组的哈希hashInt(int input) Computes hash of an int value 计算int值的哈希hashLong(long input) Computes hash of a long value 计算long值的哈希<T> HashCodehashObject(T instance, Funnel<? super T> funnel) Computes hash of an object using a Funnel 使用Funnel计算对象的哈希name()Gets the algorithm name 获取算法名称newHasher(int expectedInputSize) Creates a Hasher with expected input size hint 创建带预期输入大小提示的HashertoString()Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface HashFunction
hashBytes, hashFile, hashInputStream, hashString, hashUtf8, newHasher
-
Field Details
-
bits
protected final int bitsHash function bits -
name
Algorithm name
-
-
Constructor Details
-
AbstractHashFunction
Creates an abstract hash function 创建抽象哈希函数- Parameters:
bits- hash output bits | 哈希输出位数name- algorithm name | 算法名称
-
-
Method Details
-
bits
public int bits()Description copied from interface:HashFunctionGets the number of bits in the hash output 获取哈希输出的位数- Specified by:
bitsin interfaceHashFunction- Returns:
- number of bits | 位数
-
name
Description copied from interface:HashFunctionGets the algorithm name 获取算法名称- Specified by:
namein interfaceHashFunction- Returns:
- algorithm name | 算法名称
-
newHasher
Description copied from interface:HashFunctionCreates a Hasher with expected input size hint 创建带预期输入大小提示的Hasher- Specified by:
newHasherin interfaceHashFunction- Parameters:
expectedInputSize- expected input size in bytes | 预期输入大小(字节)- Returns:
- a new Hasher | 新的Hasher
-
hashBytes
Description copied from interface:HashFunctionComputes hash of a byte array 计算字节数组的哈希- Specified by:
hashBytesin interfaceHashFunction- Parameters:
input- input bytes | 输入字节- Returns:
- hash code | 哈希码
-
hashInt
Description copied from interface:HashFunctionComputes hash of an int value 计算int值的哈希- Specified by:
hashIntin interfaceHashFunction- Parameters:
input- int value | int值- Returns:
- hash code | 哈希码
-
hashLong
Description copied from interface:HashFunctionComputes hash of a long value 计算long值的哈希- Specified by:
hashLongin interfaceHashFunction- Parameters:
input- long value | long值- Returns:
- hash code | 哈希码
-
hashObject
Description copied from interface:HashFunctionComputes hash of an object using a Funnel 使用Funnel计算对象的哈希- Specified by:
hashObjectin interfaceHashFunction- Type Parameters:
T- object type | 对象类型- Parameters:
instance- object instance | 对象实例funnel- serialization funnel | 序列化通道- Returns:
- hash code | 哈希码
-
toString
-