返回介绍

4.5 LinkedHashMap.makeTail(LinkedEntry<K, V> e)

发布于 2024-12-23 21:09:29 字数 768 浏览 0 评论 0 收藏
/**
 * Relinks the given entry to the tail of the list. Under access ordering,
 * this method is invoked whenever the value of a  pre-existing entry is
 * read by Map.get or modified by Map.put.
 */
private void makeTail(LinkedEntry<K, V> e) {
  // Unlink e
  e.prv.nxt = e.nxt;
  e.nxt.prv = e.prv;

  // Relink e as tail
  LinkedEntry<K, V> header = this.header;
  LinkedEntry<K, V> oldTail = header.prv;
  e.nxt = header;
  e.prv = oldTail;
  oldTail.nxt = header.prv = e;
  modCount++;
}
// Unlink e
// Relink e as tail

LinkedHashMap 是双向循环链表,然后此次 LruCache.get -> LinkedHashMap.get 的数据就被放到最末尾了。

以上就是 LruCache 核心工作原理


接下来介绍 LruCache 的容量溢出策略

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。