Class HashCodes
java.lang.Object
cloud.opencode.base.hash.HashCodes
Zero-allocation hash code combining utility
零分配哈希码组合工具
Provides high-quality hash code combining using MurmurHash3's fmix32
mixing function. Unlike Objects.hash(), this utility avoids
varargs array allocation and produces better distribution through
proper mixing at each step.
使用MurmurHash3的fmix32混合函数提供高质量的哈希码组合。
与 Objects.hash() 不同,此工具避免了可变参数数组分配,
并通过每一步的正确混合产生更好的分布。
Features | 主要功能:
- Zero-allocation fixed-arity combine methods (2-8 params) - 零分配固定参数组合方法(2-8个参数)
- Chainable Combiner builder for dynamic combining - 可链式调用的Combiner构建器用于动态组合
- MurmurHash3 fmix32 mixing for excellent avalanche - MurmurHash3 fmix32混合实现优秀的雪崩效应
- Order-sensitive: combine(a,b) != combine(b,a) - 顺序敏感: combine(a,b) != combine(b,a)
Usage Examples | 使用示例:
// Fixed-arity combining (zero allocation)
// 固定参数组合(零分配)
int hash = HashCodes.combine(name.hashCode(), age);
int hash3 = HashCodes.combine(a.hashCode(), b.hashCode(), c.hashCode());
// Chainable builder for dynamic combining
// 可链式调用的构建器用于动态组合
int hash = HashCodes.start()
.add(name.hashCode())
.add(age)
.add(active)
.add(address)
.result();
Security | 安全性:
- Thread-safe: Yes (stateless utility methods) - 线程安全: 是(无状态工具方法)
- Combiner instances are NOT thread-safe - Combiner实例非线程安全
Performance | 性能特性:
- Time complexity: O(n) where n = number of values - O(n), n为值的数量
- Space complexity: O(1) - zero heap allocation for combine() - O(1) - combine()零堆分配
- Since:
- JDK 25, opencode-base-hash V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classChainable hash code combiner 可链式调用的哈希码组合器 -
Method Summary
Modifier and TypeMethodDescriptionstatic intcombine(int a, int b) Combines two hash codes into one 将两个哈希码组合为一个static intcombine(int a, int b, int c) Combines three hash codes into one 将三个哈希码组合为一个static intcombine(int a, int b, int c, int d) Combines four hash codes into one 将四个哈希码组合为一个static intcombine(int a, int b, int c, int d, int e) Combines five hash codes into one 将五个哈希码组合为一个static intcombine(int a, int b, int c, int d, int e, int f) Combines six hash codes into one 将六个哈希码组合为一个static intcombine(int a, int b, int c, int d, int e, int f, int g) Combines seven hash codes into one 将七个哈希码组合为一个static intcombine(int a, int b, int c, int d, int e, int f, int g, int h) Combines eight hash codes into one 将八个哈希码组合为一个static HashCodes.Combinerstart()Creates a new Combiner with the default seed 使用默认种子创建新的Combinerstatic HashCodes.Combinerstart(int initial) Creates a new Combiner with an initial value mixed into the seed 使用混入种子的初始值创建新的Combiner
-
Method Details
-
combine
public static int combine(int a, int b) Combines two hash codes into one 将两个哈希码组合为一个- Parameters:
a- first hash code | 第一个哈希码b- second hash code | 第二个哈希码- Returns:
- combined hash code | 组合后的哈希码
-
combine
public static int combine(int a, int b, int c) Combines three hash codes into one 将三个哈希码组合为一个- Parameters:
a- first hash code | 第一个哈希码b- second hash code | 第二个哈希码c- third hash code | 第三个哈希码- Returns:
- combined hash code | 组合后的哈希码
-
combine
public static int combine(int a, int b, int c, int d) Combines four hash codes into one 将四个哈希码组合为一个- Parameters:
a- first hash code | 第一个哈希码b- second hash code | 第二个哈希码c- third hash code | 第三个哈希码d- fourth hash code | 第四个哈希码- Returns:
- combined hash code | 组合后的哈希码
-
combine
public static int combine(int a, int b, int c, int d, int e) Combines five hash codes into one 将五个哈希码组合为一个- Parameters:
a- first hash code | 第一个哈希码b- second hash code | 第二个哈希码c- third hash code | 第三个哈希码d- fourth hash code | 第四个哈希码e- fifth hash code | 第五个哈希码- Returns:
- combined hash code | 组合后的哈希码
-
combine
public static int combine(int a, int b, int c, int d, int e, int f) Combines six hash codes into one 将六个哈希码组合为一个- Parameters:
a- first hash code | 第一个哈希码b- second hash code | 第二个哈希码c- third hash code | 第三个哈希码d- fourth hash code | 第四个哈希码e- fifth hash code | 第五个哈希码f- sixth hash code | 第六个哈希码- Returns:
- combined hash code | 组合后的哈希码
-
combine
public static int combine(int a, int b, int c, int d, int e, int f, int g) Combines seven hash codes into one 将七个哈希码组合为一个- Parameters:
a- first hash code | 第一个哈希码b- second hash code | 第二个哈希码c- third hash code | 第三个哈希码d- fourth hash code | 第四个哈希码e- fifth hash code | 第五个哈希码f- sixth hash code | 第六个哈希码g- seventh hash code | 第七个哈希码- Returns:
- combined hash code | 组合后的哈希码
-
combine
public static int combine(int a, int b, int c, int d, int e, int f, int g, int h) Combines eight hash codes into one 将八个哈希码组合为一个- Parameters:
a- first hash code | 第一个哈希码b- second hash code | 第二个哈希码c- third hash code | 第三个哈希码d- fourth hash code | 第四个哈希码e- fifth hash code | 第五个哈希码f- sixth hash code | 第六个哈希码g- seventh hash code | 第七个哈希码h- eighth hash code | 第八个哈希码- Returns:
- combined hash code | 组合后的哈希码
-
start
Creates a new Combiner with the default seed 使用默认种子创建新的Combiner- Returns:
- a new Combiner instance | 新的Combiner实例
-
start
Creates a new Combiner with an initial value mixed into the seed 使用混入种子的初始值创建新的Combiner- Parameters:
initial- initial hash value | 初始哈希值- Returns:
- a new Combiner instance | 新的Combiner实例
-