We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
func (l *LruCache) Put(k, v interface{}) { l.lock.Lock() defer l.lock.Unlock() if l.values.Len() == l.size { back := l.values.Back() l.values.Remove(back) delete(l.cacheMap, back) // 这里试图删除 back 这个元素。但是通常来说,back 元素本身不会是 map 的 key } front := l.values.PushFront(v) l.cacheMap[k] = front }
The text was updated successfully, but these errors were encountered:
我做了修改解决了这个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{} }
Sorry, something went wrong.
@cz321 欢迎提 PR
No branches or pull requests
The text was updated successfully, but these errors were encountered: