当前位置:网站首页>缓存淘汰算法初步认识(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
边栏推荐
- Plato farm is one of the four largest online IEOS in metauniverse, and the transaction on the chain is quite high
- Notes of Tang Shu's grammar class in postgraduate entrance examination English
- [problem solving] 'ASCII' codec can't encode characters in position XX XX: ordinal not in range (128)
- star
- Es keyword sorting error reason = fielddata is disabled on text fields by default Set fielddata = true on keyword in order
- Change the material of unity model as a whole
- JDBC tool class jdbcfiledateutil uploads files and date format conversion, including the latest, simplest and easiest way to upload single files and multiple files
- Click an EL checkbox to select all questions
- Error reported by Azkaban: Azkaban jobExecutor. utils. process. ProcessFailureException: Process exited with code 127
- The R language uses the timeroc package to calculate the multi time AUC value of survival data without competitive risk, and uses the confint function to calculate the confidence interval value of mul
猜你喜欢
DNS cloud school | quickly locate DNS resolution exceptions and keep these four DNS status codes in mind
JDBC tool class jdbcfiledateutil uploads files and date format conversion, including the latest, simplest and easiest way to upload single files and multiple files
上海回應“面粉官網是非法網站”:疏於運維被“黑”,警方已立案
內網滲透之DOS命令
2022dasctf APR x fat epidemic prevention challenge crypto easy_ real
Leetcode 542, 01 matrix
On BIM data redundancy theory
selenium. common. exceptions. WebDriverException: Message: ‘chromedriver‘ executable needs to be in PAT
Zdns was invited to attend the annual conference of Tencent cloud basic resources and share the 2020 domain name industry development report
LeetCode 116. Populate the next right node pointer for each node
随机推荐
ArcGIS js api 4. X submergence analysis and water submergence analysis
[PTA] l1-002 printing hourglass
How does onlyoffice solve no route to host
Don't bother tensorflow learning notes (10-12) -- Constructing a simple neural network and its visualization
RT-1052学习笔记 - GPIO架构分析
R language uses econocrats package to create microeconomic or macroeconomic map, visualize indifference function indifference curve, customize calculation intersection, and customize the parameters of
LeetCode 709、转换成小写字母
LeetCode 1337、矩阵中战斗力最弱的 K 行
LeetCode 1346、检查整数及其两倍数是否存在
16MySQL之DCL 中 COMMIT和ROllBACK
16MySQL之DCL 中 COMMIT和ROllBACK
Why does ES6 need to introduce map when JS already has object type
Commit and rollback in DCL of 16 MySQL
SQL Server Connectors By Thread Pool | DTSQLServerTP plugin instructions
DNS cloud school | analysis of hidden tunnel attacks in the hidden corner of DNS
SQL: query duplicate data and delete duplicate data
Handwritten Google's first generation distributed computing framework MapReduce
一. js的深拷贝和浅拷贝
三十.什么是vm和vc?
Operation of numpy array