Skip to content

Commit

Permalink
Fix the bug in LFUCache#put() method (#11538)
Browse files Browse the repository at this point in the history
We should not adopt the scheme of "first put new elements, then judge the capacity, and if it is full, trigger the proceedEviction() method".Instead, we should adopt the scheme of "first determine the capacity, then trigger the proceedEviction() method if it is full, and finally put in new elements".
  • Loading branch information
thisiswanghy authored Feb 14, 2023
1 parent 0f6fc11 commit 82a29fc
Showing 1 changed file with 2 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,12 @@ public V put(final K key, final V value) {
freqTable[0].addLastNode(node);
map.put(key, node);
} else {
node = freqTable[0].addLast(key, value);
map.put(key, node);
curSize++;
if (curSize > capacity) {
proceedEviction();
}
node = freqTable[0].addLast(key, value);
map.put(key, node);
}
} finally {
lock.unlock();
Expand Down

0 comments on commit 82a29fc

Please sign in to comment.