HashMap 的 hash函数 jdk1.8
来源:互联网 发布:nba比赛个人数据统计 编辑:程序博客网 时间:2024/06/05 04:57
/**
* Computes key.hashCode() and spreads (XORs) higher bits of hash
* to lower. Because the table uses power-of-two masking, sets of
* hashes that vary only in bits above the current mask will
* always collide. (Among known examples are sets of Float keys
* holding consecutive whole numbers in small tables.) So we
* apply a transform that spreads the impact of higher bits
* downward. There is a tradeoff between speed, utility, and
* quality of bit-spreading. Because many common sets of hashes
* are already reasonably distributed (so don't benefit from
* spreading), and because we use trees to handle large sets of
* collisions in bins, we just XOR some shifted bits in the
* cheapest possible way to reduce systematic lossage, as well as
* to incorporate impact of the highest bits that would otherwise
* never be used in index calculations because of table bounds.
*/
static final int hash(Object key) {
int h;
return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
* Computes key.hashCode() and spreads (XORs) higher bits of hash
* to lower. Because the table uses power-of-two masking, sets of
* hashes that vary only in bits above the current mask will
* always collide. (Among known examples are sets of Float keys
* holding consecutive whole numbers in small tables.) So we
* apply a transform that spreads the impact of higher bits
* downward. There is a tradeoff between speed, utility, and
* quality of bit-spreading. Because many common sets of hashes
* are already reasonably distributed (so don't benefit from
* spreading), and because we use trees to handle large sets of
* collisions in bins, we just XOR some shifted bits in the
* cheapest possible way to reduce systematic lossage, as well as
* to incorporate impact of the highest bits that would otherwise
* never be used in index calculations because of table bounds.
*/
static final int hash(Object key) {
int h;
return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}
言下之意,做一个简单的bit移位,使得高位能够作用于hash。
0 0
- HashMap 的 hash函数 jdk1.8
- HashMap引起的事故:jdk1.7和jdk1.8下的hash函数的不同
- JDK1.8 使用平衡树处理HashMap的高频hash冲突问题
- HashMap的jdk1.8分析
- Java HashMap的hash和indexFor函数
- Java HashMap的hash函数实现
- JDK1.8的HashMap源码分析
- jdk1.8的HashMap和ConcurrentHashMap
- HashMap的工作原理 - JDK1.8
- jdk1.8对HashMap的优化
- jdk1.8 hashmap
- 数据结构--jdk1.8 HashMap
- HashMap(JDK1.8)
- HashMap(jdk1.8)
- JDK1.8 HashMap
- Jdk1.8 HashMap解读
- jdk1.8 HashMap源码分析(put函数)
- jdk1.8 HashMap源码分析(构造函数)
- 使用c++driver实现mongodb空间数据查询
- 我的java学习笔记(一)
- 蓝桥杯 - 带分数 (DFS)
- 如何加载指定路径的Logback.xml
- SGU 200 Cracking RSA (高斯消元)
- HashMap 的 hash函数 jdk1.8
- PHP还是ASP.NET ?
- Leetcode: Remove Element
- 黑马程序员——对象方法与类方法
- python列表删除重复元素的三种方法
- 虚幻4——蓝图在脚本之间的交互
- 漫游Kafka设计篇之性能优化
- STL之 next_permutation
- palyframework学习日记一二三四