common/lru: shorten return names

This commit is contained in:
Felix Lange 2025-05-14 11:51:58 +02:00 committed by lightclient
parent 1c64c74f07
commit b04157fafe
No known key found for this signature in database
GPG key ID: 657913021EF45A6A

View file

@ -52,32 +52,32 @@ func (c *BasicLRU[K, V]) Add(key K, value V) (evicted bool) {
}
// Add3 adds a value to the cache. If an item was evicted to store the new one, it returns the evicted item.
func (c *BasicLRU[K, V]) Add3(key K, value V) (evKey K, evItem V, evicted bool) {
func (c *BasicLRU[K, V]) Add3(key K, value V) (ek K, ev V, evicted bool) {
item, ok := c.items[key]
if ok {
item.value = value
c.items[key] = item
c.list.moveToFront(item.elem)
return evKey, evItem, false
return ek, ev, false
}
var elem *listElem[K]
if c.Len() >= c.cap {
elem = c.list.removeLast()
evicted = true
evKey = elem.v
evItem = c.items[evKey].value
delete(c.items, evKey)
ek = elem.v
ev = c.items[ek].value
delete(c.items, ek)
} else {
elem = new(listElem[K])
}
// Store the new item.
// Note that, if another item was evicted, we re-use its list element here.
// Note that if another item was evicted, we re-use its list element here.
elem.v = key
c.items[key] = cacheItem[K, V]{elem, value}
c.list.pushElem(elem)
return evKey, evItem, evicted
return ek, ev, evicted
}
// Contains reports whether the given key exists in the cache.