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

什么是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

原文地址:https://www.cnblogs.com/linyihai/p/14531183.html