mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
libutil: Format lru-cache.hh
Rip off the band-aid for further refactors. The diff is very small, so it makes to get it out of the way first.
This commit is contained in:
parent
e088ab3eaf
commit
90d70aa4c9
2 changed files with 14 additions and 6 deletions
|
@ -360,7 +360,6 @@
|
|||
''^src/libutil/linux/namespaces\.cc$''
|
||||
''^src/libutil/logging\.cc$''
|
||||
''^src/libutil/include/nix/util/logging\.hh$''
|
||||
''^src/libutil/include/nix/util/lru-cache\.hh$''
|
||||
''^src/libutil/memory-source-accessor\.cc$''
|
||||
''^src/libutil/include/nix/util/memory-source-accessor\.hh$''
|
||||
''^src/libutil/include/nix/util/pool\.hh$''
|
||||
|
|
|
@ -25,21 +25,28 @@ private:
|
|||
using Data = std::map<Key, std::pair<LRUIterator, Value>>;
|
||||
using LRU = std::list<typename Data::iterator>;
|
||||
|
||||
struct LRUIterator { typename LRU::iterator it; };
|
||||
struct LRUIterator
|
||||
{
|
||||
typename LRU::iterator it;
|
||||
};
|
||||
|
||||
Data data;
|
||||
LRU lru;
|
||||
|
||||
public:
|
||||
|
||||
LRUCache(size_t capacity) : capacity(capacity) { }
|
||||
LRUCache(size_t capacity)
|
||||
: capacity(capacity)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert or upsert an item in the cache.
|
||||
*/
|
||||
void upsert(const Key & key, const Value & value)
|
||||
{
|
||||
if (capacity == 0) return;
|
||||
if (capacity == 0)
|
||||
return;
|
||||
|
||||
erase(key);
|
||||
|
||||
|
@ -64,7 +71,8 @@ public:
|
|||
bool erase(const Key & key)
|
||||
{
|
||||
auto i = data.find(key);
|
||||
if (i == data.end()) return false;
|
||||
if (i == data.end())
|
||||
return false;
|
||||
lru.erase(i->second.first.it);
|
||||
data.erase(i);
|
||||
return true;
|
||||
|
@ -77,7 +85,8 @@ public:
|
|||
std::optional<Value> get(const Key & key)
|
||||
{
|
||||
auto i = data.find(key);
|
||||
if (i == data.end()) return {};
|
||||
if (i == data.end())
|
||||
return {};
|
||||
|
||||
/**
|
||||
* Move this item to the back of the LRU list.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue