HashMap扩容函数解读
2016-02-01 23:46
302 查看
void resize(int newCapacity) { Entry[] oldTable = table; int oldCapacity = oldTable.length; if (oldCapacity == MAXIMUM_CAPACITY) { threshold = Integer.MAX_VALUE; return; } Entry[] newTable = new Entry[newCapacity]; transfer(newTable, initHashSeedAsNeeded(newCapacity)); table = newTable; threshold = (int) Math.min(newCapacity * loadFactor, MAXIMUM_CAPACITY + 1); } /** * Transfers all entries from current table to newTable. */ void transfer(Entry[] newTable, boolean rehash) { int newCapacity = newTable.length; for (Entry<K, V> e : table) { while (null != e) { Entry<K, V> next = e.next; if (rehash) { e.hash = null == e.key ? 0 : hash(e.key); } int i = indexFor(e.hash, newCapacity); e.next = newTable[i]; newTable[i] = e; e = next; } } }
相关文章推荐
- AR--未来技术提前探索<4>[在汉明码上叠加一个视频]
- POJ 3259 -- 最短路径 ( bellman ford算法, 允许负权边)
- 密码学初级教程(五)消息认证码MAC-Message Authentication Code
- 括号配对问题
- 定时器的应用(一):延时提示框
- 虚拟服务器Windwos server 2003远程安装SQL server 2008R2提示0x2d2816fe错误解决办法
- SSH项目开发中,将jsp页面放在WEB-INF的原因解析
- Java初学笔记
- Error retrieving parent for item: No resource found that matches the given name 'android:TextAppeara
- SGU 536 Berland Chess(状压+BFS)
- 《秦始皇》读书笔记
- node-webkit is renamed NW.js
- VS使用总结
- POJ 1743:Musical Theme
- 3-2 wordcount执行流程 wordcount流程
- vim显示^M的解决办法
- java List集合类的用法
- ZOJ 2853 Evolution (矩阵快速幂+数学)
- 3D旋转动画的自定义FlopView
- win7系统SQLServer2008 基本操作和sqlcmd 实用语法