自定义 LRU 页面置换算法"/>
自定义 LRU 页面置换算法
LRU 页面置换算法
LRU释义说明
class MyLRU {constructor(n) {this.size = n // 初始化内存条this.cacheMap = new Map() // 新插入的数据排在后面,旧数据放在前面}put(domain, info) {this.cacheMap.has(domain) && this.cacheMap.delete(domain)this.cacheMap.size >= this.size && this.cacheMap.delete(this.cacheMap.keys().next().value)this.cacheMap.set(domain, info)}get(domain) {if (!this.cacheMap.has(domain)) {return false}const info = this.cacheMap.get(domain)this.put(domain, info)return info}
}
更多推荐
自定义 LRU 页面置换算法
发布评论