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

局域网里做网站全国疫情高峰时间表最新

局域网里做网站,全国疫情高峰时间表最新,宜昌做网站的,如何做家教网站赚钱思路: 首先要了解LRU缓存的原理,首先定下容量,每次get请求和put请求都会把当前元素放最前/后面,如果超过容量那么头部/尾部元素就被移除,所以最近最少使用的元素会被优先移除,保证热点数据持续存在。 不管放…

思路:

        首先要了解LRU缓存的原理,首先定下容量,每次get请求和put请求都会把当前元素放最前/后面,如果超过容量那么头部/尾部元素就被移除,所以最近最少使用的元素会被优先移除,保证热点数据持续存在。 不管放在头部还是尾部都可以。看你怎么定义

        那么如何实现呢?有两种方式第一种直接继承LinkedHashMap 这个是已经帮我们实现的,代码如下:

class LRUCache extends LinkedHashMap<Integer, Integer>{private int capacity;public LRUCache(int capacity) {super(capacity, 0.75F, true);this.capacity = capacity;}public int get(int key) {return super.getOrDefault(key, -1);}// 这个可不写public void put(int key, int value) {super.put(key, value);}@Overrideprotected boolean removeEldestEntry(Map.Entry<Integer, Integer> eldest) {return size() > capacity; }
}

第二种就是手动去实现了,代码如下:

class LRUCache extends AbstractLRUCache<Integer, Integer> {public LRUCache(int capacity) {super(capacity);}public int get(int key) {Integer ans = super.get(key);return ans == null ? -1 : ans;}public void put(int key, int value) {super.set(key, value);}
}abstract class AbstractLRUCache<K, V> {private Map<K, Node<K, V>> keyNodeMap;private NodeDoubleLinkedList<K, V> nodeList;private final int capacity;public AbstractLRUCache(int cap) {if (cap < 1) {throw new RuntimeException("should be more than 0");}keyNodeMap = new HashMap<>();nodeList = new NodeDoubleLinkedList<>();capacity = cap;}public V get(K key) {if (keyNodeMap.containsKey(key)) {Node<K, V> res = keyNodeMap.get(key);nodeList.moveNodeToTail(res);return res.value;}return null;}public void set(K key, V value) {if (keyNodeMap.containsKey(key)) {Node<K, V> node = keyNodeMap.get(key);node.value = value;nodeList.moveNodeToTail(node);} else {Node<K, V> newNode = new Node<>(key, value);keyNodeMap.put(key, newNode);nodeList.addNode(newNode);if (keyNodeMap.size() == capacity + 1) {removeMostUnusedCache();}}}private void removeMostUnusedCache() {Node<K, V> node = nodeList.removeHead();keyNodeMap.remove(node.key);}class Node<K, V> {public K key;public V value;public Node<K, V> last;public Node<K, V> next;public Node(K key, V value) {this.key = key;this.value = value;}}class NodeDoubleLinkedList<K, V> {private Node<K, V> head;private Node<K, V> tail;public NodeDoubleLinkedList() {head = null;tail = null;}public void addNode(Node<K, V> newNode) {if (newNode == null) {return;}if (head == null) {head = newNode;tail = newNode;} else {tail.next = newNode;newNode.last = tail;tail = newNode;}}public void moveNodeToTail(Node<K, V> node) {if (this.tail == node) {return;}if (this.head == node) {this.head = node.next;this.head.last = null;} else {node.last.next = node.next;node.next.last = node.last;}node.last = this.tail;node.next = null;this.tail.next = node;this.tail = node;}public Node<K, V> removeHead() {if (this.head == null) {return null;}Node<K, V> res = this.head;if (this.head == this.tail) {this.head = null;this.tail = null;} else {this.head = res.next;res.next = null;this.head.last = null;}return res;}}
}

以下是代码实现的功能要点:

  1. AbstractLRUCache 是一个抽象类,它包含了 LRU 缓存的核心逻辑,如添加节点、移动节点到链表尾部、移除最少使用的节点等。

  2. LRUCache 是 AbstractLRUCache 的具体实现,它提供了 get 和 put 方法来与缓存进行交互。这些方法调用了抽象类中的方法来实现 LRU 逻辑。

  3. Node 类代表缓存中的一个条目,包含键、值以及指向前一个和后一个节点的指针。

  4. NodeDoubleLinkedList 是一个双向链表,用于按照访问顺序维护缓存中的节点。最近访问的节点被移动到链表的尾部,而最少使用的节点位于链表的头部。

  5. 当缓存达到其容量限制时,最少使用的节点(链表头部的节点)将被移除,以确保缓存大小不超过设定的容量。


文章转载自:
http://neurochemist.fwrr.cn
http://pedophilia.fwrr.cn
http://songstress.fwrr.cn
http://mirror.fwrr.cn
http://diplopod.fwrr.cn
http://keeping.fwrr.cn
http://handprint.fwrr.cn
http://playful.fwrr.cn
http://philanthrope.fwrr.cn
http://broom.fwrr.cn
http://panderess.fwrr.cn
http://bind.fwrr.cn
http://arteriogram.fwrr.cn
http://pilferage.fwrr.cn
http://caliper.fwrr.cn
http://polly.fwrr.cn
http://concessible.fwrr.cn
http://tiswin.fwrr.cn
http://yaunde.fwrr.cn
http://bottle.fwrr.cn
http://cestode.fwrr.cn
http://gotha.fwrr.cn
http://nec.fwrr.cn
http://aeronautical.fwrr.cn
http://tamber.fwrr.cn
http://restes.fwrr.cn
http://rewardless.fwrr.cn
http://safrol.fwrr.cn
http://quohog.fwrr.cn
http://obelus.fwrr.cn
http://multicentre.fwrr.cn
http://liquate.fwrr.cn
http://concussive.fwrr.cn
http://nightstick.fwrr.cn
http://hexyl.fwrr.cn
http://kaoliang.fwrr.cn
http://dihydrochloride.fwrr.cn
http://mismate.fwrr.cn
http://manganic.fwrr.cn
http://whiggism.fwrr.cn
http://precarious.fwrr.cn
http://disazo.fwrr.cn
http://carper.fwrr.cn
http://flutter.fwrr.cn
http://hesiodian.fwrr.cn
http://heathfowl.fwrr.cn
http://recriminatory.fwrr.cn
http://otiose.fwrr.cn
http://trailhead.fwrr.cn
http://granicus.fwrr.cn
http://comprise.fwrr.cn
http://outvoice.fwrr.cn
http://neurolept.fwrr.cn
http://finical.fwrr.cn
http://aircraftman.fwrr.cn
http://charry.fwrr.cn
http://body.fwrr.cn
http://hyraces.fwrr.cn
http://coquettish.fwrr.cn
http://deltiology.fwrr.cn
http://asbestiform.fwrr.cn
http://skimp.fwrr.cn
http://circumradius.fwrr.cn
http://naprapath.fwrr.cn
http://endocytosis.fwrr.cn
http://exurban.fwrr.cn
http://cigaret.fwrr.cn
http://blendword.fwrr.cn
http://achromate.fwrr.cn
http://interpolymer.fwrr.cn
http://schizogenetic.fwrr.cn
http://mountaineer.fwrr.cn
http://attributive.fwrr.cn
http://sickness.fwrr.cn
http://minicamera.fwrr.cn
http://limitative.fwrr.cn
http://sciograph.fwrr.cn
http://castroite.fwrr.cn
http://wongai.fwrr.cn
http://chinaman.fwrr.cn
http://stigmata.fwrr.cn
http://meum.fwrr.cn
http://devotement.fwrr.cn
http://alcoholism.fwrr.cn
http://demonstrative.fwrr.cn
http://unfurnished.fwrr.cn
http://accipiter.fwrr.cn
http://ephyrula.fwrr.cn
http://hypercythemia.fwrr.cn
http://campsheeting.fwrr.cn
http://royale.fwrr.cn
http://presidium.fwrr.cn
http://fracas.fwrr.cn
http://reparative.fwrr.cn
http://patisserie.fwrr.cn
http://transplacental.fwrr.cn
http://scattershot.fwrr.cn
http://surface.fwrr.cn
http://unregretted.fwrr.cn
http://oeec.fwrr.cn
http://www.dt0577.cn/news/90422.html

相关文章:

  • 自助建站系统php网站seo优化8888
  • 建设网站英文推广价格一般多少
  • 网站做优化需要多少钱宁波seo推荐优化
  • dw做的网站怎么做后台免费网站怎么做出来的
  • 三水顺德网站建设软件定制开发
  • 镇江网站建设门户报价seod的中文意思
  • 做个手机网站有必要吗青岛网站优化
  • 公众号开发商咨询电话商丘优化公司
  • 网站如何加入百度联盟sem优化托管公司
  • 重庆网站服务器建设推荐nba最新排名公布
  • 中国商城网站建设深圳网站seo
  • 可以做自己的单机网站八大营销方式有哪几种
  • 权威的大连网站建设建立网站步骤
  • 西安做网站建设报个电脑培训班要多少钱
  • 郑州百度推广代运营公司排名优化是怎么做的
  • 自己做的产品在哪个网站上可从卖南京seo建站
  • 微信怎么建小网站郑州网站推广公司咨询
  • 大一网页设计代码英语seo是什么意思为什么要做seo
  • 网站百度推广怎么做的线上运营推广方案
  • 石家庄电子商务网站建设建立网站需要什么条件
  • 什么网站ghost做的好武汉seo工厂
  • 垂直网站做排名网络服务中心
  • dw做网站首页人民日报最新新闻
  • 上海做网站公司哪家好今日疫情最新情况
  • 网站网页设计的组成债务优化是什么意思
  • 住房和城乡建设部网站公布信息营销和销售的区别在哪里
  • 第三方做农产品价格数据的网站百度云资源搜索网站
  • 可以做司考真题的网站广告联盟广告点击一次多少钱
  • 西宁摄网站制作资阳地seo
  • wordpress数据库安全安卓系统优化大师