Interface Hasher
- All Known Implementing Classes:
AbstractHashFunction.AbstractHasher, AbstractHashFunction.BufferedHasher
public interface Hasher
Streaming hash calculator interface
流式哈希计算器接口
Provides a fluent API for incrementally building hash values by adding data piece by piece. This is useful for hashing large data or combining multiple values into a single hash.
提供流畅的API,通过逐块添加数据来增量构建哈希值。 这对于哈希大数据或将多个值组合成单个哈希非常有用。
Features | 主要功能:
- Fluent method chaining - 流畅的方法链
- Multiple data type support - 多种数据类型支持
- Object hashing via Funnel - 通过Funnel的对象哈希
Usage Examples | 使用示例:
Hasher hasher = OpenHash.murmur3_128().newHasher();
HashCode hash = hasher
.putUtf8("Hello")
.putInt(42)
.putLong(System.currentTimeMillis())
.hash();
Security | 安全性:
- Thread-safe: No (stateful) - 线程安全: 否(有状态)
- Since:
- JDK 25, opencode-base-hash V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionhash()Computes the hash value 计算哈希值putBoolean(boolean b) Adds a boolean value to the hash computation 向哈希计算添加boolean值putByte(byte b) Adds a byte to the hash computation 向哈希计算添加一个字节putBytes(byte[] bytes) Adds a byte array to the hash computation 向哈希计算添加字节数组putBytes(byte[] bytes, int offset, int length) Adds a portion of a byte array to the hash computation 向哈希计算添加字节数组的一部分putBytes(ByteBuffer buffer) Adds a ByteBuffer to the hash computation 向哈希计算添加ByteBufferputChar(char c) Adds a char value to the hash computation 向哈希计算添加char值putDouble(double d) Adds a double value to the hash computation 向哈希计算添加double值putFloat(float f) Adds a float value to the hash computation 向哈希计算添加float值putInt(int i) Adds an int value to the hash computation 向哈希计算添加int值putLong(long l) Adds a long value to the hash computation 向哈希计算添加long值<T> HasherAdds an object using a Funnel to the hash computation 使用Funnel向哈希计算添加对象putShort(short s) Adds a short value to the hash computation 向哈希计算添加short值putString(CharSequence charSequence, Charset charset) Adds a string with specified charset to the hash computation 向哈希计算添加指定字符集的字符串default HasherputUtf8(CharSequence charSequence) Adds a UTF-8 string to the hash computation 向哈希计算添加UTF-8字符串
-
Method Details
-
putByte
Adds a byte to the hash computation 向哈希计算添加一个字节- Parameters:
b- byte value | 字节值- Returns:
- this hasher | 此hasher
-
putBytes
Adds a byte array to the hash computation 向哈希计算添加字节数组- Parameters:
bytes- byte array | 字节数组- Returns:
- this hasher | 此hasher
-
putBytes
Adds a portion of a byte array to the hash computation 向哈希计算添加字节数组的一部分- Parameters:
bytes- byte array | 字节数组offset- starting offset | 起始偏移length- number of bytes | 字节数- Returns:
- this hasher | 此hasher
-
putBytes
Adds a ByteBuffer to the hash computation 向哈希计算添加ByteBuffer- Parameters:
buffer- byte buffer | 字节缓冲区- Returns:
- this hasher | 此hasher
-
putShort
Adds a short value to the hash computation 向哈希计算添加short值- Parameters:
s- short value | short值- Returns:
- this hasher | 此hasher
-
putInt
Adds an int value to the hash computation 向哈希计算添加int值- Parameters:
i- int value | int值- Returns:
- this hasher | 此hasher
-
putLong
Adds a long value to the hash computation 向哈希计算添加long值- Parameters:
l- long value | long值- Returns:
- this hasher | 此hasher
-
putFloat
Adds a float value to the hash computation 向哈希计算添加float值- Parameters:
f- float value | float值- Returns:
- this hasher | 此hasher
-
putDouble
Adds a double value to the hash computation 向哈希计算添加double值- Parameters:
d- double value | double值- Returns:
- this hasher | 此hasher
-
putBoolean
Adds a boolean value to the hash computation 向哈希计算添加boolean值- Parameters:
b- boolean value | boolean值- Returns:
- this hasher | 此hasher
-
putChar
Adds a char value to the hash computation 向哈希计算添加char值- Parameters:
c- char value | char值- Returns:
- this hasher | 此hasher
-
putString
Adds a string with specified charset to the hash computation 向哈希计算添加指定字符集的字符串- Parameters:
charSequence- string | 字符串charset- character set | 字符集- Returns:
- this hasher | 此hasher
-
putUtf8
Adds a UTF-8 string to the hash computation 向哈希计算添加UTF-8字符串- Parameters:
charSequence- string | 字符串- Returns:
- this hasher | 此hasher
-
putObject
-
hash
HashCode hash()Computes the hash value 计算哈希值This method can only be called once. After calling hash(), this Hasher should not be used again.
此方法只能调用一次。调用hash()后,此Hasher不应再使用。
- Returns:
- computed hash code | 计算的哈希码
-