Skip to content

Commit

Permalink
impl Keys func
Browse files Browse the repository at this point in the history
  • Loading branch information
knbr13 committed May 29, 2024
1 parent aa4b3ee commit 60b97a9
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lfu_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,21 @@ func (src *LFUCache[K, V]) CopyTo(dst *LFUCache[K, V]) {
}
}

func (l *LFUCache[K, V]) Keys() []K {
l.mu.RLock()
defer l.mu.RUnlock()

keys := make([]K, 0, l.Count())

for k, v := range l.m {
if v.Value.(*lfuItem[K, V]).expireAt == nil || !v.Value.(*lfuItem[K, V]).expireAt.Before(time.Now()) {
keys = append(keys, k)
}
}

return keys
}

func (l *LFUCache[K, V]) Count() int {
l.mu.RLock()
defer l.mu.RUnlock()
Expand Down

0 comments on commit 60b97a9

Please sign in to comment.