Skip to content

Commit 0c7f963

Browse files
committed
fixed some comments
1 parent 7de70b9 commit 0c7f963

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

fifo/fifo.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
)
66

77
// Cache is used a FIFO (First in first out) cache replacement policy.
8+
//
89
// In FIFO the item that enter the cache first is evicted first
910
// w/o any regard of how often or how many times it was accessed before.
1011
type Cache[K comparable, V any] struct {
@@ -38,7 +39,7 @@ func WithCapacity(cap int) Option {
3839
}
3940
}
4041

41-
// NewCache creates a new cache.
42+
// NewCache creates a new FIFO cache whose capacity is the default size (128).
4243
func NewCache[K comparable, V any](opts ...Option) *Cache[K, V] {
4344
o := newOptions()
4445
for _, optFunc := range opts {

lfu/lfu.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import (
44
"container/heap"
55
)
66

7-
// Cache is a thread safe LRU cache
7+
// Cache is used a LFU (Least-frequently used) cache replacement policy.
8+
//
9+
// Counts how often an item is needed. Those that are used least often are discarded first.
10+
// This works very similar to LRU except that instead of storing the value of how recently
11+
// a block was accessed, we store the value of how many times it was accessed. So of course
12+
// while running an access sequence we will replace a block which was used fewest times from our cache.
813
type Cache[K comparable, V any] struct {
914
cap int
1015
queue *priorityQueue[K, V]

lru/lru.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import (
44
"container/list"
55
)
66

7-
// Cache is a thread safe LRU cache
7+
// Cache is used a LRU (Least recently used) cache replacement policy.
8+
//
9+
// Discards the least recently used items first. This algorithm requires
10+
// keeping track of what was used when, which is expensive if one wants
11+
// to make sure the algorithm always discards the least recently used item.
812
type Cache[K comparable, V any] struct {
913
cap int
1014
list *list.List

0 commit comments

Comments
 (0)