【底层代码欣赏】—— LinkedHashMap之afterNodeAccess方法

// 在访问元素之后,将该元素放到双向链表的尾巴处
void
afterNodeAccess(Node<K,V> e) { // move node to last LinkedHashMap.Entry<K,V> last; if (accessOrder && (last = tail) != e) { LinkedHashMap.Entry<K,V> p = (LinkedHashMap.Entry<K,V>)e, b = p.before, a = p.after; p.after = null; if (b == null) head = a; else b.after = a; if (a != null) a.before = b; else last = b; if (last == null) head = p; else { p.before = last; last.after = p; } tail = p; ++modCount; } }

https://leetcode-cn.com/problems/lru-cache/solution/yuan-yu-linkedhashmapyuan-ma-by-jeromememory/

关于LinkedHashMap的解析见如上链接!

posted @ 2021-08-16 11:02  吾辈当奋斗-生生不息  阅读(159)  评论(0)    收藏  举报