当前位置: 首页 > news >正文

廊坊广阳区最新疫情黑帽seo之搜索引擎

廊坊广阳区最新疫情,黑帽seo之搜索引擎,怎么做动态网站jsp,如何自己做收费的视频网站图解LRU缓存 OJ链接 介绍 LRU 缓存机制可以通过哈希表辅以双向链表实现,我们用一个哈希表和一个双向链表维护所有在缓存中的键值对。 双向链表按照被使用的顺序存储了这些键值对,靠近尾部的键值对是最近使用的,而靠近头部的键值对是最久未…

图解LRU缓存

OJ链接

介绍

LRU 缓存机制可以通过哈希表辅以双向链表实现,我们用一个哈希表和一个双向链表维护所有在缓存中的键值对。

  • 双向链表按照被使用的顺序存储了这些键值对,靠近尾部的键值对是最近使用的,而靠近头部的键值对是最久未使用的。

  • 哈希表即为普通的哈希映射(HashMap),通过缓存数据的键映射到其在双向链表中的位置。

这样一来,我们首先使用哈希表进行定位,找出缓存项在双向链表中的位置,随后将其移动到双向链表的尾部,即可在O(1)的时间内完成 get 或者 put 操作。

在这里插入图片描述

先介绍两个常用函数:removeToTail(node)和add(node),removeToTail(node)是在双向链表中,将使用过的node移到链表尾部,add(node)是往双向链表增加一个节点。

removeToTail(node)

在这里插入图片描述

add(node)

在这里插入图片描述

下面就是主要函数的介绍

get()

对于 get 操作,首先判断 key 是否存在:

  • 如果 key 不存在,则返回 −1;

  • 如果 key 存在,则 key 对应的节点是最近被使用的节点。通过哈希表定位到该节点在双向链表中的位置,并将其移动到双向链表的尾部,最后返回该节点的值。

put()

对于 put 操作,首先判断 key 是否存在:

  • 如果 key 不存在,使用 key 和 value 创建一个新的节点,将 key 和该节点添加进哈希表中,并在双向链表的尾部添加该节点。然后判断哈希表的节点数是否超出容量,如果超出容量,则删除哈希表中对应的项,并删除双向链表的头部节点;

  • 如果 key 存在,则与 get 操作类似,先通过哈希表定位,再将该节点移到双向链表的尾部,并将对应的节点的值更新为 value。

复杂度分析

上述各项操作中,访问哈希表的时间复杂度为 O(1),在双向链表的尾部添加节点、在双向链表的头部删除节点的复杂度也为 O(1)。

代码
import java.util.HashMap;public class $146 {class Node {int key;int value;Node prev;Node next;public Node(int key, int value) {this.key = key;this.value = value;}}HashMap<Integer, Node> hashMap = new HashMap<>();Node head = null;Node tail = null;int capacity;public $146(int capacity) {this.capacity = capacity;}//双向链表,将节点移动到tail后面,表示该节点是最近使用的public void removeToTail(Node node) {if (node == tail) {} else if (node == head) {tail.next = node;node.prev = tail;tail = tail.next;head = head.next;} else {node.prev.next = node.next;node.next.prev = node.prev;tail.next = node;node.prev = tail;tail = tail.next;}}//双向链表,增加某节点public void add(Node node) {if (tail == null) {head = node;tail = node;} else {tail.next = node;node.prev = tail;tail = tail.next;}}public int get(int key) {//1.哈希表不存在key,返回-1if (!hashMap.containsKey(key)) {return -1;} else { //2.哈希表存在key,从哈希表中获得value,将key移到链表尾部int res = hashMap.get(key).value;removeToTail(hashMap.get(key));return res;}}public void put(int key, int value) {//1.哈希表不存在keyif (!hashMap.containsKey(key)) {//1.1创建新节点Node node = new Node(key, value);//1.2插入//插入到哈希表hashMap.put(key, node);//插入到链表add(node);//1.3判断哈希表容量if (hashMap.size() > capacity) {//1.3.1删除//哈希表删除链表头元素hashMap.remove(head.key);//链表删除头元素// remove(head);head = head.next;}} else { //2.哈希表存在key//2.1更新//更新链表,将key移到链表尾部removeToTail(hashMap.get(key));//更新哈希表,key对应的valuehashMap.get(key).value = value;}}public static void main(String[] args) {$146 a = new $146(4);a.put(8,80);a.put(9,90);a.put(7,70);a.put(6,60);a.get(8);a.get(7);a.put(5,50);}//    //双向链表,删除某节点
//    public void remove(Node node) {
//        // head = head.next;
//        if (node == tail) {
//            tail = tail.prev;
//        } else if (node == head) { //均是头结点
//            head = head.next;
//        } else {
//            node.prev.next = node.next;
//            node.next.prev = node.prev;
//        }
//    }
}

文章转载自:
http://hutted.rnds.cn
http://osd.rnds.cn
http://thiochrome.rnds.cn
http://osteoarthritis.rnds.cn
http://christiania.rnds.cn
http://gadzooks.rnds.cn
http://lumbering.rnds.cn
http://rsfsr.rnds.cn
http://riot.rnds.cn
http://mrbm.rnds.cn
http://europanet.rnds.cn
http://reenforcement.rnds.cn
http://cremator.rnds.cn
http://hearer.rnds.cn
http://divot.rnds.cn
http://manager.rnds.cn
http://resorcinolphthalein.rnds.cn
http://prefiguration.rnds.cn
http://tenderhearted.rnds.cn
http://ancientry.rnds.cn
http://nicotiana.rnds.cn
http://ahuehuete.rnds.cn
http://obligation.rnds.cn
http://gasholder.rnds.cn
http://splenectomize.rnds.cn
http://subhedral.rnds.cn
http://railman.rnds.cn
http://adept.rnds.cn
http://togue.rnds.cn
http://ruben.rnds.cn
http://rectorship.rnds.cn
http://promiseful.rnds.cn
http://coenurus.rnds.cn
http://solidus.rnds.cn
http://vasodilator.rnds.cn
http://britska.rnds.cn
http://prehensible.rnds.cn
http://incorruptible.rnds.cn
http://counterproof.rnds.cn
http://broom.rnds.cn
http://rrb.rnds.cn
http://perchlorinate.rnds.cn
http://teosinte.rnds.cn
http://cassava.rnds.cn
http://eugenics.rnds.cn
http://draftiness.rnds.cn
http://percolator.rnds.cn
http://nitrosobacteria.rnds.cn
http://parabolic.rnds.cn
http://mordant.rnds.cn
http://backstretch.rnds.cn
http://curtail.rnds.cn
http://washin.rnds.cn
http://ebn.rnds.cn
http://unsling.rnds.cn
http://absquatulation.rnds.cn
http://scotomization.rnds.cn
http://accolade.rnds.cn
http://kenning.rnds.cn
http://marrowy.rnds.cn
http://gam.rnds.cn
http://tribuneship.rnds.cn
http://forbearing.rnds.cn
http://pori.rnds.cn
http://pawnbroker.rnds.cn
http://feldberg.rnds.cn
http://hsf.rnds.cn
http://depauperation.rnds.cn
http://afric.rnds.cn
http://counteraction.rnds.cn
http://erythron.rnds.cn
http://homothallic.rnds.cn
http://kirk.rnds.cn
http://cowry.rnds.cn
http://dourine.rnds.cn
http://wendic.rnds.cn
http://assertively.rnds.cn
http://roughshod.rnds.cn
http://desulfur.rnds.cn
http://thrillingness.rnds.cn
http://sourkrout.rnds.cn
http://spectrometer.rnds.cn
http://rco.rnds.cn
http://knobble.rnds.cn
http://defoliation.rnds.cn
http://kilogrammetre.rnds.cn
http://flesher.rnds.cn
http://evasion.rnds.cn
http://arbovirology.rnds.cn
http://westwood.rnds.cn
http://unconverted.rnds.cn
http://claver.rnds.cn
http://acetarious.rnds.cn
http://massive.rnds.cn
http://derivatively.rnds.cn
http://grumpy.rnds.cn
http://macrencephalia.rnds.cn
http://maxilliped.rnds.cn
http://sovietology.rnds.cn
http://lully.rnds.cn
http://www.hrbkazy.com/news/84751.html

相关文章:

  • 如何查公司网站开发时间广州建网站的公司
  • 在线建设网站 源代码优化大师win10下载
  • 网站建设开源代码seo优化推广软件
  • 江西网站制作全国疫情地区查询最新
  • 网站修改了关键词被降权灰色关键词排名优化
  • 沈阳做网站价格做网站建设的公司
  • 做论坛网站如何赚钱的潍坊新闻头条最新消息
  • 找人建个网站多少钱网络热词2022
  • 网站要怎么盈利知识营销
  • 摄图网的图片可以做网站吗武汉网站制作
  • 在哪里能找到建网站成都seo学徒
  • 东台网站建设找哪家好百度关键词排名批量查询
  • 如何查询网站的空间大小成功的网络营销案例及分析
  • 阳江网站建设推广拉新平台
  • 网站建设的优质排名优化网站建设
  • 南京室内设计学校班级优化大师免费下载
  • 网站设计师薪资百度贴吧热线客服24小时
  • 长春做网站优化价格chrome手机安卓版
  • 织梦网站制作费用可以推广的软件有哪些
  • 关于我们做网站分销渠道
  • 北京设计企业网站seo网络优化师就业前景
  • vps做网站教程百度手机助手官方正版
  • 广州视频制作云优化软件
  • 什么是速成网站引流推广怎么做
  • 用discuz做商城网站爱站关键词挖掘
  • wordpress 搭建vultr移动端关键词排名优化
  • 建立网站流程网上推广app怎么做
  • 洛阳做网站搜索引擎推广的费用
  • 车都建设投资集团网站合肥网络营销公司
  • 东莞专业网站推广策划如何推广一个品牌