老师我看到一个golang 实现lru cache
来源:4-1 Python常用内置算法与数据结构常考题

我是一只小蜗牛
2019-10-24
type Cache struct {
// MaxEntries is the maximum number of cache entries before
// an item is evicted. Zero means no limit.
MaxEntries int
// OnEvicted optionally specifies a callback function to be
// executed when an entry is purged from the cache.
OnEvicted func(key Key, value interface{})
ll *list.List
cache map[interface{}]*list.Element
}
这里的代码为什么不能直接使用ll, 而不省去cache, 是因为get的时候好拿吗?虽然这里cache field是指针
写回答
1回答
-
PegasusWang
2020-03-10
这个可能和你另一个问题类似,lru 里边 map 是为了快速获取 key对应的 value 数据,而链表是为了保存顺序用的。
00
相似问题