Loading system/common/lru.h +3 −1 Original line number Diff line number Diff line Loading @@ -119,8 +119,10 @@ class LruCache { // remove tail if (lru_map_.size() == capacity_) { lru_map_.erase(node_list_.back().first); K key_evicted = node_list_.back().first; V value_evicted = node_list_.back().second; node_list_.pop_back(); lru_eviction_callback_(node_list_.back().first, node_list_.back().second); lru_eviction_callback_(key_evicted, value_evicted); value_popped = true; } // insert to dummy next; Loading system/common/lru_unittest.cc +5 −4 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ TEST(BluetoothLruCacheTest, LruCacheMainTest1) { int* value = new int(0); int dummy = 0; int* pointer = &dummy; auto callback = [pointer](int a, int b) { (*pointer) = 1; }; auto callback = [pointer](int a, int b) { (*pointer) = a * b; }; LruCache<int, int> cache(3, "testing", callback); // capacity = 3; cache.Put(1, 10); EXPECT_EQ(cache.Size(), 1); Loading @@ -51,8 +51,8 @@ TEST(BluetoothLruCacheTest, LruCacheMainTest1) { EXPECT_EQ(cache.Size(), 3); cache.Put(4, 40); EXPECT_EQ(dummy, 1); // 2, 3, 4 should be in cache, 1 should not EXPECT_EQ(dummy, 10); // 2, 3, 4 should be in cache, 1 is evicted EXPECT_FALSE(cache.Get(1, value)); EXPECT_TRUE(cache.Get(4, value)); EXPECT_EQ(*value, 40); Loading @@ -63,7 +63,8 @@ TEST(BluetoothLruCacheTest, LruCacheMainTest1) { cache.Put(5, 50); EXPECT_EQ(cache.Size(), 3); // 2, 3, 5 should be in cache EXPECT_EQ(dummy, 160); // 2, 3, 5 should be in cache, 4 is evicted EXPECT_TRUE(cache.Remove(3)); cache.Put(6, 60); Loading Loading
system/common/lru.h +3 −1 Original line number Diff line number Diff line Loading @@ -119,8 +119,10 @@ class LruCache { // remove tail if (lru_map_.size() == capacity_) { lru_map_.erase(node_list_.back().first); K key_evicted = node_list_.back().first; V value_evicted = node_list_.back().second; node_list_.pop_back(); lru_eviction_callback_(node_list_.back().first, node_list_.back().second); lru_eviction_callback_(key_evicted, value_evicted); value_popped = true; } // insert to dummy next; Loading
system/common/lru_unittest.cc +5 −4 Original line number Diff line number Diff line Loading @@ -32,7 +32,7 @@ TEST(BluetoothLruCacheTest, LruCacheMainTest1) { int* value = new int(0); int dummy = 0; int* pointer = &dummy; auto callback = [pointer](int a, int b) { (*pointer) = 1; }; auto callback = [pointer](int a, int b) { (*pointer) = a * b; }; LruCache<int, int> cache(3, "testing", callback); // capacity = 3; cache.Put(1, 10); EXPECT_EQ(cache.Size(), 1); Loading @@ -51,8 +51,8 @@ TEST(BluetoothLruCacheTest, LruCacheMainTest1) { EXPECT_EQ(cache.Size(), 3); cache.Put(4, 40); EXPECT_EQ(dummy, 1); // 2, 3, 4 should be in cache, 1 should not EXPECT_EQ(dummy, 10); // 2, 3, 4 should be in cache, 1 is evicted EXPECT_FALSE(cache.Get(1, value)); EXPECT_TRUE(cache.Get(4, value)); EXPECT_EQ(*value, 40); Loading @@ -63,7 +63,8 @@ TEST(BluetoothLruCacheTest, LruCacheMainTest1) { cache.Put(5, 50); EXPECT_EQ(cache.Size(), 3); // 2, 3, 5 should be in cache EXPECT_EQ(dummy, 160); // 2, 3, 5 should be in cache, 4 is evicted EXPECT_TRUE(cache.Remove(3)); cache.Put(6, 60); Loading