Skip to content

Align RemoveOldest Function with Pseudo-Code from the Paper #1

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions lru/lru.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ func (c *Cache) Add(key Key, value interface{}) {
ee.Value.(*entry).value = value
return
}
ele := c.ll.PushFront(&entry{key, false, value})
c.cache[key] = ele
if c.MaxEntries != 0 && c.ll.Len() > c.MaxEntries {
if c.MaxEntries != 0 && c.ll.Len() >= c.MaxEntries {
c.RemoveOldest()
}
ele := c.ll.PushFront(&entry{key, false, value})
c.cache[key] = ele
}

// Get looks up a key's value from the cache.
Expand Down Expand Up @@ -105,12 +105,12 @@ func (c *Cache) RemoveOldest() {
if ele == nil {
ele = c.ll.Back()
}
for ele != nil && ele.Value.(*entry).visited {
for ele.Value.(*entry).visited {
ele.Value.(*entry).visited = false
ele = ele.Prev()
}
if ele == nil {
println("Error: RemoveOldest cannot find element")
if ele == nil {
ele = c.ll.Back()
}
}
c.ptr = ele.Prev()
c.removeElement(ele)
Expand Down