代码拉取完成,页面将自动刷新
package list
import (
C "gitee.com/ljfirst/algo-go-sdk/common/constant"
)
/**
* @author ljfirst
* @version V1.0
* @date 2023/6/28 17:19
* @author-Email ljfirst@mail.ustc.edu.cn
* @blogURL https://blog.csdn.net/ljfirst
* @description 最近最久未使用算法
* LRU: The Least Recently Used
* */
type LRUCache struct {
LimitSize int
searchMap map[interface{}]*Node // 快速定位 key
list *DuplexList
}
func NewLRUCache(options ...C.Options) *LRUCache {
opt := C.NewOptions(options...)
lru := &LRUCache{
LimitSize: 3,
searchMap: make(map[interface{}]*Node),
list: NewDuplexList(),
}
lru.LimitSize = opt.LimitSize
return lru
}
func (m *LRUCache) Set(key, value interface{}) {
// 是否存在:存在则更新的
if v, exist := m.searchMap[key]; exist {
m.list.Delete(v)
//m.list.InsertIndex(v, 0)
}
// 是否需要内存淘汰
if m.list.Size() == m.LimitSize {
}
// 插入
}
func (m *LRUCache) Get(key interface{}) interface{} { return nil }
func (m *LRUCache) Delete(key interface{}) {}
func (m *LRUCache) Length() int { return 0 }
func (m *LRUCache) Clear() {}
func (m *LRUCache) GetAttribute() *C.Attribute {
return &C.Attribute{
Tags: []string{C.Cache},
Desc: &C.Desc{
Name: "LRUCache",
NameCn: "最近最久未使用算法",
},
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。