-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LRU 模块Put 方法有 bug #9
Labels
bug
Something isn't working
Comments
我做了修改解决了这个bug: func (l *LRUCache) Put(k,v interface{}) {
l.lock.Lock()
defer l.lock.Unlock()
if e,ok := l.cacheMap[k]; ok {
l.values.Remove(e)
delete(l.cacheMap,e.Value.(Pair).Key)
}
if l.values.Len() == l.cap {
back := l.values.Back()
l.values.Remove(back)
delete(l.cacheMap,back.Value.(Pair).Key)
}
front := l.values.PushFront(Pair{
Key: k,
Val: v,
})
l.cacheMap[k] = front
}
type Pair struct {
Key,Val interface{}
} |
@cz321 欢迎提 PR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The text was updated successfully, but these errors were encountered: