当前位置:网站首页>缓存淘汰算法初步认识(LRU和LFU)
缓存淘汰算法初步认识(LRU和LFU)
2022-04-23 20:28:00 【游戏编程】
API: 即 Application Programming Interface (应用程序编程接口)。操作系统会将一些复杂的底层操作封装成简单的函数,程序员只需要调用相应的函数就实现底层细节操作。(c中有printf、scanf、fopen,在c++中API包括函数和类)
缓存淘汰算法 :内存容量是有限的,当你要缓存的数据超出容量,就得有部分数据删除,这时候哪些数据删除,哪些数据保留,就是LRU算法和LFU算法,FU强调的是 访问次数 ,而LRU强调的是 访问时间 。
LRU: 即 Least Recently Used (最近最少使用算法)。把长期不使用的数据被认定为无用数据,在缓存容量满了后,会优先删除这些被认定的数据。
LRU 为达到存入键值对和获取键值对的时间复杂度最小,使用 哈希链表 来实现算法核心,即哈希表存key,每个key映射双向链表中的键值对,以此来达到快速搜索链表的key(哈希表搜索时间复杂度O(1))。

LFU: 即 Least Frequently Used (最不经常使用算法)。把一定时期内被访问次数最少的数据看作在将来被访问到的几率也是最小的。在缓存容量满了后,会优先删除这些被认定的数据。
LFU 为了按照频率选择淘汰,所以采用的 双哈希表 为核心算法,第一个哈希表 fre_table,其key是访问的频次,其value是一个双向链表,双向链表的每一个节点包含三个元素:key,value,以及count。第二个哈希表key_table,其key即为双向链表的key,value为指向链表中相应位置的指针。

(后续补充代码部分)
作者:易风尘
游戏编程 ️,一个游戏开发收藏夹~
如果图片长时间未显示,请使用Chrome内核浏览器。
版权声明
本文为[游戏编程]所创,转载请带上原文链接,感谢
https://www.233tw.com/algorithm/118822
边栏推荐
- Numpy mathematical function & logical function
- JDBC tool class jdbcconutil gets the connection to the database
- Error reported by Azkaban: Azkaban jobExecutor. utils. process. ProcessFailureException: Process exited with code 64
- DNS cloud school | analysis of hidden tunnel attacks in the hidden corner of DNS
- Intersection calculation of straight line and plane in PCL point cloud processing (53)
- 內網滲透之DOS命令
- Browser - learning notes
- Change the material of unity model as a whole
- How to protect ECs from hacker attacks?
- Use the rolling division method to find the maximum common divisor of two numbers
猜你喜欢
Handwritten Google's first generation distributed computing framework MapReduce
Automatically fill in body temperature and win10 task plan
Identification of bolt points in aerial photography based on perception
SIGIR'22 "Microsoft" CTR estimation: using context information to promote feature representation learning
Es keyword sorting error reason = fielddata is disabled on text fields by default Set fielddata = true on keyword in order
【PTA】L1-002 打印沙漏
Computing the intersection of two planes in PCL point cloud processing (51)
PIP installation package reports an error. Could not find a version that satisfies the requirement pymysql (from versions: none)
內網滲透之DOS命令
上海回應“面粉官網是非法網站”:疏於運維被“黑”,警方已立案
随机推荐
RT-1052学习笔记 - GPIO架构分析
Rédaction de thèses 19: différences entre les thèses de conférence et les thèses périodiques
[PTA] l2-011 play with binary tree
Leetcode 1351. Negative numbers in statistical ordered matrices
Sqoop imports tinyint type fields to boolean type
R language uses the preprocess function of caret package for data preprocessing: BoxCox transform all data columns (convert non normal distribution data columns to normal distribution data and can not
SQL gets the latest record of the data table
Latest investigation and progress of building intelligence based on sati
Identification of bolt points in aerial photography based on perception
Monte Carlo py solves the area problem! (save pupils Series)
【PTA】L2-011 玩转二叉树
LeetCode 709、转换成小写字母
[PTA] get rid of singles
go-zero框架数据库方面避坑指南
LeetCode 20、有效的括号
Recommend an open source free drawing software draw IO exportable vector graph
【PTA】整除光棍
The ODB model calculates the data and outputs it to excel
Customize timeline component styles
Confusion about thread blocking after calling the read () method of wrapper flow