LinkedHashMap随笔
LinkedHashMap继承了HashMap, 采用了HashMap的散列结构 因此其随机查询速度很快. 同时由于其修改HashMap.Entry, 添加 before/after Entry<K,V>两个元素用于保存最后添加的元素 以保持顺序结构.
private transient Entry<K,V> header;public void clear() {super.clear();header.before = header.after = header;}private static class Entry<K,V> extends HashMap.Entry<K,V> {// These fields comprise the doubly linked list used for iteration.Entry<K,V> before, after;Entry(int hash, K key, V value, HashMap.Entry<K,V> next) {super(hash, key, value, next);}/*** Removes this entry from the linked list.*/private void remove() {before.after = after;after.before = before;}/*** Inserts this entry before the specified existing entry in the list.*/private void addBefore(Entry<K,V> existingEntry) {after = existingEntry;before = existingEntry.before;before.after = this;after.before = this;}/*** This method is invoked by the superclass whenever the value* of a pre-existing entry is read by Map.get or modified by Map.set.* If the enclosing Map is access-ordered, it moves the entry* to the end of the list; otherwise, it does nothing.*/void recordAccess(HashMap<K,V> m) {LinkedHashMap<K,V> lm = (LinkedHashMap<K,V>)m;if (lm.accessOrder) {lm.modCount++;remove();addBefore(lm.header);}}void recordRemoval(HashMap<K,V> m) {remove();}}/*** Called by superclass constructors and pseudoconstructors (clone,* readObject) before any entries are inserted into the map. Initializes* the chain.*/void init() {header = new Entry<K,V>(-1, null, null, null);header.before = header.after = header;}/*** Transfers all entries to new table array. This method is called* by superclass resize. It is overridden for performance, as it is* faster to iterate using our linked list.*/void transfer(HashMap.Entry[] newTable) {int newCapacity = newTable.length;for (Entry<K,V> e = header.after; e != header; e = e.after) {int index = indexFor(e.hash, newCapacity);e.next = newTable[index];newTable[index] = e;}}
转载于:https://www.cnblogs.com/davidwang/archive/2012/12/18/2823740.html
LinkedHashMap随笔相关推荐
- Echo团队Alpha冲刺随笔 - 第九天
项目冲刺情况 进展 已经进入测试阶段,正在消除系统的bug 问题 通过测试,找出了系统中存在的较多bug...... 体会 测试太重要了,很多原本以为没什么bug,一测就能找到好几个,而且改个bug真 ...
- 第一篇随笔——新的开端
新的开端 这是我第一次开通博客也是第一次在博客上写随笔,这既是博客的新开端也是JAVA学习的新开端,希望能好好经营这第一个博客~. 觉得自己专业吗?对专业的期望 对于这个问题我不得不坦然承认虽然进入信 ...
- LinkedHashMap and LinkedHashSet
LinkedHashMap实现了Map接口,是HashMap的直接子类,它同时满足HashMap和linked list的某些特性.可将LinkedHashMap看作采用linked list增强的H ...
- 我先了解一下博客园创建随笔/文章/日记的过程与三者的区别(隐私等级,是否审核等)...
我先了解一下博客园创建随笔/文章/日记的过程与三者的区别(隐私等级,是否审核等) 转载于:https://www.cnblogs.com/Totooria-Hyperion/p/5260289.htm ...
- web高性能开发系列随笔
在BlogJava里写了一些关于高性能WEB开发的随笔,因为都是跟前端技术相关(html,http,js,css等),所以也贴到博客园来,吸收下人气. 1. HTTP服务器. 2.性能测试工具推荐 3 ...
- LInkedHashMap实现最近被使用(LRU)缓存
在最近的面试中,我曾被多次问到,怎么实现一个最近最少使用(LRU)的缓存.缓存可以通过哈希表来实现,然而为这个缓存增加大小限制会变成另一个有意思的问题.现在我们看一下怎么实现. 最近最少使用缓存的回收 ...
- 彻底理解HashMap及LinkedHashMap
欢迎关注方志朋的博客,回复"666"获面试宝典 来源:https://blog.csdn.net/fuzhongmin05/article/details/104355841 Ha ...
- HashMap和LinkedHashMap的区别
转自:https://www.cnblogs.com/yuexzh/p/7486264.html HashMap,LinkedHashMap,TreeMap都属于Map Map 主要用于存储键(key ...
- cuda图像处理_CUDA随笔之图像直方图(优化历程)
在忙忙碌碌许久之后,终于有时间写 "CUDA随笔" 系列的第二集了! 这次给大家带来了一个图像处理的应用例子:计算图片的直方图. 虽然使用CUDA可以很轻松地在性能上超越CPU,如 ...
- 博客园的“随笔、文章、新闻、日记有啥区别”
随笔:是一些比较杂乱的技术类东西且有待修改和讨论的文章,假如是原创则只是作者随时提笔写下的内容,而并没有经过太多的推敲,甚至措辞也没有得到很合理的运用. 文章:直接获得的有正规性质的文章,或当随笔中的 ...
最新文章
- 树莓派4b上安装tensorflow+keras
- sublime text3 package control 报错
- cup过高是什么意思_做青和焙火有什么关系?
- 再有人问你MySql的隔离级别,直接把这篇文章发给他!
- 面试题 01.09. 字符串轮转
- 锤子系统宣布回归 或将推新品
- 我是WPF菜鸟之(4)---关于XAML与逻辑代码
- Unity Shader播放序列帧动画
- 饿了么:日订单量超900万的架构设计及演进之路
- ASP.NET控件and代码实现二级联动查询
- java keytool下载_Java中Keytool工具的使用总结(一)
- c语言解线性方程组矩阵形势,c语言解线性方程组.docx
- epub文件如何打开?
- 微信小程序服务器云端,微信小程序云端解决方案.PDF
- 渥太华大学计算机学硕录取过程,西农计算机拟录取名单公布,初试第一被刷,289分倒数第一上岸...
- WORD 毕设页眉页码目录标题 排版
- MATLAB机器人机械臂运动学正逆解、动力学建模仿真与轨迹规划
- 传统行业+互联网思维
- 你真的懂Linux内核中的阻塞和异步通知机制吗?(花了五天整理,墙裂推荐!)
- 带exp在线计算机计算器使用,电脑系统自带科学计算器使用方法