Skip to content

Commit

Permalink
implement CopyTo func
Browse files Browse the repository at this point in the history
  • Loading branch information
knbr13 committed May 29, 2024
1 parent 03a3286 commit c751660
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lfu_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ func (src *LFUCache[K, V]) TransferTo(dst *LFUCache[K, V]) {
}
}

func (src *LFUCache[K, V]) CopyTo(dst *LFUCache[K, V]) {
src.mu.RLock()
defer src.mu.RUnlock()

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

func (l *LFUCache[K, V]) Delete(k K) {
l.mu.Lock()
defer l.mu.Unlock()
Expand Down

0 comments on commit c751660

Please sign in to comment.