Class OpenHash
java.lang.Object
cloud.opencode.base.hash.OpenHash
Hash utility facade class
哈希工具门面类
Provides a unified entry point for all hash functions and data structures. This is the main API for hash operations in the library.
为所有哈希函数和数据结构提供统一的入口点。 这是库中哈希操作的主要API。
Features | 主要功能:
- Non-cryptographic hashes: MurmurHash3, xxHash, FNV-1a, CRC32, SipHash, Adler32 - 非加密哈希
- Cryptographic hashes: MD5, SHA-1, SHA-256, SHA-384, SHA-512, SHA-3 - 加密哈希
- HMAC: HMAC-MD5, HMAC-SHA1, HMAC-SHA256, HMAC-SHA384, HMAC-SHA512 - HMAC消息认证
- Consistent hash ring - 一致性哈希环
- Bloom filter - 布隆过滤器
- Counting bloom filter - 计数布隆过滤器
- SimHash for text similarity - SimHash用于文本相似度
- HashCodes combiner for efficient hashCode() - HashCodes组合器用于高效hashCode()
Usage Examples | 使用示例:
// Hash a string
HashCode hash = OpenHash.murmur3_128().hashUtf8("Hello World");
// Consistent hash ring
ConsistentHash<String> ring = OpenHash.<String>consistentHash()
.addNode("server1", "192.168.1.1")
.build();
// Bloom filter
BloomFilter<String> filter = OpenHash.<String>bloomFilter()
.funnel(Funnel.STRING_FUNNEL)
.expectedInsertions(1_000_000)
.build();
// SimHash
SimHash simHash = OpenHash.simHash().nGram(3).build();
Security | 安全性:
- Thread-safe: Yes (factory class) - 线程安全: 是(工厂类)
Performance | 性能特性:
- Time complexity: O(n) where n = input size - O(n), n为输入大小
- Space complexity: O(1) for hash computation - 哈希计算 O(1)
- Since:
- JDK 25, opencode-base-hash V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic HashFunctionadler32()Adler-32 checksum Adler-32 校验和static <T> BloomFilterBuilder<T> Creates a bloom filter builder 创建布隆过滤器构建器static <T> BloomFilterBuilder<T> bloomFilter(Funnel<? super T> funnel) Creates a bloom filter builder with funnel 使用funnel创建布隆过滤器构建器static HashCodecombineOrdered(HashCode... hashCodes) Combines hash codes in order 按顺序组合哈希码static HashCodecombineUnordered(HashCode... hashCodes) Combines hash codes unordered (XOR) 无序组合哈希码(XOR)static <T> ConsistentHashBuilder<T> Creates a consistent hash ring builder 创建一致性哈希环构建器static <T> CountingBloomFilter.Builder<T> Creates a counting bloom filter builder 创建计数布隆过滤器构建器static <T> CountingBloomFilter.Builder<T> countingBloomFilter(Funnel<? super T> funnel) Creates a counting bloom filter builder with funnel 使用funnel创建计数布隆过滤器构建器static HashFunctioncrc32()CRC32 CRC32static HashFunctioncrc32c()CRC32C (Castagnoli) CRC32C (Castagnoli)static HashFunctionfnv1a_32()FNV-1a 32-bit FNV-1a 32位static HashFunctionfnv1a_64()FNV-1a 64-bit FNV-1a 64位static HashCodehash(byte[] input, HashFunction function) Hashes a byte array 哈希字节数组static HashCodehash(CharSequence input, Charset charset, HashFunction function) Hashes a string 哈希字符串static HashFunctionhmacMd5(byte[] key) HMAC-MD5 HMAC-MD5static HashFunctionhmacSha1(byte[] key) HMAC-SHA1 HMAC-SHA1static HashFunctionhmacSha256(byte[] key) HMAC-SHA256 HMAC-SHA256static HashFunctionhmacSha384(byte[] key) HMAC-SHA384 HMAC-SHA384static HashFunctionhmacSha512(byte[] key) HMAC-SHA512 HMAC-SHA512static HashFunctionmd5()MD5 (for checksums only, not secure) MD5(仅用于校验,不安全)static HashFunctionMurmurHash3 128-bit MurmurHash3 128位static HashFunctionmurmur3_128(int seed) MurmurHash3 128-bit with seed 带种子的MurmurHash3 128位static HashFunctionMurmurHash3 32-bit MurmurHash3 32位static HashFunctionmurmur3_32(int seed) MurmurHash3 32-bit with seed 带种子的MurmurHash3 32位static HashFunctionsha1()SHA-1 (for checksums only, not secure) SHA-1(仅用于校验,不安全)static HashFunctionsha256()SHA-256 SHA-256static HashFunctionsha3_256()SHA3-256 SHA3-256static HashFunctionsha3_512()SHA3-512 SHA3-512static HashFunctionsha384()SHA-384 SHA-384static HashFunctionsha512()SHA-512 SHA-512static SimHashBuildersimHash()Creates a SimHash builder 创建SimHash构建器static HashFunctionSipHash-2-4 with default key 默认密钥的 SipHash-2-4static HashFunctionsipHash24(long k0, long k1) SipHash-2-4 with specified key 指定密钥的 SipHash-2-4static HashFunctionxxHash64()xxHash 64-bit xxHash 64位static HashFunctionxxHash64(long seed) xxHash 64-bit with seed 带种子的xxHash 64位
-
Method Details
-
murmur3_32
MurmurHash3 32-bit MurmurHash3 32位- Returns:
- hash function | 哈希函数
-
murmur3_32
MurmurHash3 32-bit with seed 带种子的MurmurHash3 32位- Parameters:
seed- seed value | 种子值- Returns:
- hash function | 哈希函数
-
murmur3_128
MurmurHash3 128-bit MurmurHash3 128位- Returns:
- hash function | 哈希函数
-
murmur3_128
MurmurHash3 128-bit with seed 带种子的MurmurHash3 128位- Parameters:
seed- seed value | 种子值- Returns:
- hash function | 哈希函数
-
xxHash64
-
xxHash64
xxHash 64-bit with seed 带种子的xxHash 64位- Parameters:
seed- seed value | 种子值- Returns:
- hash function | 哈希函数
-
fnv1a_32
-
fnv1a_64
-
crc32
-
crc32c
CRC32C (Castagnoli) CRC32C (Castagnoli)- Returns:
- hash function | 哈希函数
-
adler32
-
sipHash24
SipHash-2-4 with default key 默认密钥的 SipHash-2-4- Returns:
- hash function | 哈希函数
-
sipHash24
SipHash-2-4 with specified key 指定密钥的 SipHash-2-4- Parameters:
k0- first key half | 密钥前半部分k1- second key half | 密钥后半部分- Returns:
- hash function | 哈希函数
-
md5
MD5 (for checksums only, not secure) MD5(仅用于校验,不安全)- Returns:
- hash function | 哈希函数
-
sha1
SHA-1 (for checksums only, not secure) SHA-1(仅用于校验,不安全)- Returns:
- hash function | 哈希函数
-
sha256
-
sha512
-
sha3_256
-
sha384
-
sha3_512
-
hmacMd5
HMAC-MD5 HMAC-MD5- Parameters:
key- secret key bytes | 密钥字节- Returns:
- hash function | 哈希函数
-
hmacSha1
HMAC-SHA1 HMAC-SHA1- Parameters:
key- secret key bytes | 密钥字节- Returns:
- hash function | 哈希函数
-
hmacSha256
HMAC-SHA256 HMAC-SHA256- Parameters:
key- secret key bytes | 密钥字节- Returns:
- hash function | 哈希函数
-
hmacSha384
HMAC-SHA384 HMAC-SHA384- Parameters:
key- secret key bytes | 密钥字节- Returns:
- hash function | 哈希函数
-
hmacSha512
HMAC-SHA512 HMAC-SHA512- Parameters:
key- secret key bytes | 密钥字节- Returns:
- hash function | 哈希函数
-
hash
Hashes a string 哈希字符串- Parameters:
input- input string | 输入字符串charset- character set | 字符集function- hash function | 哈希函数- Returns:
- hash code | 哈希码
-
hash
Hashes a byte array 哈希字节数组- Parameters:
input- input bytes | 输入字节function- hash function | 哈希函数- Returns:
- hash code | 哈希码
-
combineOrdered
-
combineUnordered
-
consistentHash
Creates a consistent hash ring builder 创建一致性哈希环构建器- Type Parameters:
T- node data type | 节点数据类型- Returns:
- builder | 构建器
-
bloomFilter
Creates a bloom filter builder 创建布隆过滤器构建器- Type Parameters:
T- element type | 元素类型- Returns:
- builder | 构建器
-
bloomFilter
Creates a bloom filter builder with funnel 使用funnel创建布隆过滤器构建器- Type Parameters:
T- element type | 元素类型- Parameters:
funnel- element funnel | 元素funnel- Returns:
- builder | 构建器
-
countingBloomFilter
Creates a counting bloom filter builder 创建计数布隆过滤器构建器- Type Parameters:
T- element type | 元素类型- Returns:
- builder | 构建器
-
countingBloomFilter
Creates a counting bloom filter builder with funnel 使用funnel创建计数布隆过滤器构建器- Type Parameters:
T- element type | 元素类型- Parameters:
funnel- element funnel | 元素funnel- Returns:
- builder | 构建器
-
simHash
Creates a SimHash builder 创建SimHash构建器- Returns:
- builder | 构建器
-