双链表 哈希 go 实现lFU 缓存算法

时间:2021-03-15 11:36:50   收藏:0   阅读:0

什么是LFU

LFU
Least frequently used, 基于访问的频次和时间来淘汰数据。比如缓存满了,使用LFU算法,可以淘汰掉访问频次最少且访问时间靠后的元素。

leetcode也有相应的题目,只要实现Get, Put接口即可。

本文除了实现Get, Put, 还实现了GetIterator和GetAll接口,接口如下

func (lfu *LFUCache) Get(key interface{}) interface{}
func (lfu *LFUCache) Put(key interface{}, value interface{}) 
func (lfu *LFUCache) GetIterator() func() *dbNode
func (lfu *LFUCache) GetAll() []interface{} 

完整代码见github

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!