Skip to content

Commit

Permalink
minor improve
Browse files Browse the repository at this point in the history
  • Loading branch information
Yiling-J committed Oct 17, 2024
1 parent 6fc915c commit 897bfb2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
1 change: 1 addition & 0 deletions internal/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ func (s *Store[K, V]) setShard(shard *Shard[K, V], hash uint64, key K, value V,
entry.weight.Store(cost)
entry.policyWeight = 0
entry.queueIndex.Store(-2)
entry.flag = Flag{}
s.setEntry(hash, shard, cost, entry, nvmClean)
return shard, entry, true

Expand Down
8 changes: 1 addition & 7 deletions internal/tlfu.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ func (t *TinyLfu[K, V]) climb() {
delta := current - t.hr
var diff int8
if delta > 0.0 {
newFactor := int8(t.lruFactor) + t.step
if t.step < 0 {
t.step -= 1
} else {
Expand All @@ -60,7 +61,6 @@ func (t *TinyLfu[K, V]) climb() {
} else if t.step > 13 {
t.step = 13
}
newFactor := int8(t.lruFactor) + t.step
if newFactor < 0 {
newFactor = 0
} else if newFactor > 16 {
Expand Down Expand Up @@ -89,11 +89,6 @@ func (t *TinyLfu[K, V]) climb() {
}

func (t *TinyLfu[K, V]) Set(entry *Entry[K, V]) *Entry[K, V] {
t.counter++
if t.counter > 10*t.size {
t.climb()
t.counter = 0
}
if entry.meta.prev == nil {
if victim := t.slru.victim(); victim != nil {
freq := int(t.sketch.Estimate(t.hasher.hash(entry.key)))
Expand Down Expand Up @@ -166,7 +161,6 @@ func (t *TinyLfu[K, V]) EvictEntries() (evicted bool) {
if entry == nil {
break
}
evicted = true
t.removeCallback(entry)
}
return
Expand Down

0 comments on commit 897bfb2

Please sign in to comment.