package main
import "fmt"
type Node struct {
Key int
Value int
freq int
pre *Node
next *Node
}
type LFUCache struct {
limit int
HashMap map[int]*Node
head *Node
end *Node
}
func LFUConstructor(capacity int) LFUCache{
lfuCache := LFUCache{
}
lfuCache.limit = capacity
lfuCache.HashMap = make(map[int]*Node, capacity)
return lfuCache
}
func(l *LFUCache) Get(key int) int {
if value ,ok := l.HashMap[key] ;ok {
value.freq ++
l.refreshNode(value)
Golang 实现LFU缓存淘汰算法
最新推荐文章于 2024-07-16 12:13:37 发布