Skip to content

Commit 1be70bd

Browse files
authored
rename LRU field capacity->size, maxCapacity->capacity (TheAlgorithms#612)
1 parent 41fa294 commit 1be70bd

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

cache/lru.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@ type item struct {
1010
}
1111

1212
type LRU struct {
13-
dl *linkedlist.Doubly[any]
14-
capacity int
15-
maxCapacity int
16-
storage map[string]*linkedlist.Node[any]
13+
dl *linkedlist.Doubly[any]
14+
size int
15+
capacity int
16+
storage map[string]*linkedlist.Node[any]
1717
}
1818

1919
// NewLRU represent initiate lru cache with capacity
2020
func NewLRU(capacity int) LRU {
2121
return LRU{
22-
dl: linkedlist.NewDoubly[any](),
23-
storage: make(map[string]*linkedlist.Node[any], capacity),
24-
capacity: 0,
25-
maxCapacity: capacity,
22+
dl: linkedlist.NewDoubly[any](),
23+
storage: make(map[string]*linkedlist.Node[any], capacity),
24+
size: 0,
25+
capacity: capacity,
2626
}
2727
}
2828

@@ -49,17 +49,17 @@ func (c *LRU) Put(key string, value any) {
4949
return
5050
}
5151

52-
if c.capacity >= c.maxCapacity {
52+
if c.size >= c.capacity {
5353
e := c.dl.Front()
5454
dk := e.Val.(item).key
5555
c.dl.Remove(e)
5656
delete(c.storage, dk)
57-
c.capacity--
57+
c.size--
5858
}
5959

6060
n := item{key: key, value: value}
6161
c.dl.AddAtEnd(n)
6262
ne := c.dl.Back()
6363
c.storage[key] = ne
64-
c.capacity++
64+
c.size++
6565
}

0 commit comments

Comments
 (0)