mirror of
https://github.com/dragonflydb/dragonfly.git
synced 2025-05-11 18:35:46 +02:00
fix(SimpleLruCounter): Correctly set bumped node's next (#2346)
This commit is contained in:
parent
69f269e808
commit
c7093c40e5
2 changed files with 28 additions and 2 deletions
|
@ -84,7 +84,7 @@ void SimpleLruCounter::BumpToHead(uint32_t index) {
|
|||
node_arr_[node.prev].next = node.next;
|
||||
node_arr_[node.next].prev = node.prev;
|
||||
node.prev = tail;
|
||||
node.prev = head_;
|
||||
node.next = head_;
|
||||
head_ = index;
|
||||
}
|
||||
}; // namespace dfly
|
||||
|
|
|
@ -13,9 +13,10 @@ namespace dfly {
|
|||
|
||||
class SimpleLruTest : public ::testing::Test {
|
||||
protected:
|
||||
SimpleLruTest() : cache_(4) {
|
||||
SimpleLruTest() : cache_(kSize) {
|
||||
}
|
||||
|
||||
const size_t kSize = 4;
|
||||
SimpleLruCounter cache_;
|
||||
};
|
||||
|
||||
|
@ -45,4 +46,29 @@ TEST_F(SimpleLruTest, Basic) {
|
|||
ASSERT_EQ(6, cache_.Get("f"));
|
||||
}
|
||||
|
||||
TEST_F(SimpleLruTest, DifferentOrder) {
|
||||
for (uint32_t i = 0; i < kSize * 2; ++i) {
|
||||
cache_.Put(absl::StrCat(i), i);
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < kSize; ++i) {
|
||||
EXPECT_EQ(nullopt, cache_.Get(absl::StrCat(i)));
|
||||
}
|
||||
for (uint32_t i = kSize; i < kSize * 2; ++i) {
|
||||
EXPECT_EQ(i, cache_.Get(absl::StrCat(i)));
|
||||
}
|
||||
|
||||
for (uint32_t i = kSize; i > 0; --i) {
|
||||
cache_.Put(absl::StrCat(i), i);
|
||||
}
|
||||
cache_.Put("0", 0);
|
||||
|
||||
for (uint32_t i = 0; i < kSize; ++i) {
|
||||
EXPECT_EQ(i, cache_.Get(absl::StrCat(i)));
|
||||
}
|
||||
for (uint32_t i = kSize; i < kSize * 2; ++i) {
|
||||
EXPECT_EQ(nullopt, cache_.Get(absl::StrCat(i)));
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace dfly
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue