We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LRU是Least Recently Used的缩写,即最近最少使用,是一种常用的页面置换算法[2],选择最近最久未使用的页面予以淘汰。该算法赋予每个页面[3]一个访问字段,用来记录一个页面自上次被访问以来所经历的时间 t,当须淘汰一个页面时,选择现有页面中其 t 值最大的,即最近最少使用的页面予以淘汰。
The text was updated successfully, but these errors were encountered:
/** * @param {number} capacity */ var LRUCache = function(capacity) { this.map = new Map() this.capacity = capacity }; /** * @param {number} key * @return {number} */ LRUCache.prototype.get = function(key) { if(this.map.has(key)){ const value = this.map.get(key) // 更新存储位置 this.map.delete(key) this.map.set(key,value) return value } return - 1 }; /** * @param {number} key * @param {number} value * @return {void} */ LRUCache.prototype.put = function(key, value) { if(this.map.has(key)){ this.map.delete(key) } this.map.set(key,value) // 如果此时超过了最长可存储范围 if(this.map.size > this.capacity){ // 删除 map 中最久未使用的元素 this.map.delete(this.map.keys().next().value) } };
Sorry, something went wrong.
No branches or pull requests
LRU是Least Recently Used的缩写,即最近最少使用,是一种常用的页面置换算法[2],选择最近最久未使用的页面予以淘汰。该算法赋予每个页面[3]一个访问字段,用来记录一个页面自上次被访问以来所经历的时间 t,当须淘汰一个页面时,选择现有页面中其 t 值最大的,即最近最少使用的页面予以淘汰。
The text was updated successfully, but these errors were encountered: