1#ifndef YAZE_UTIL_LRU_CACHE_H_
2#define YAZE_UTIL_LRU_CACHE_H_
32template <
typename Key,
typename Value>
41 Value*
Insert(
const Key& key, Value value) {
51 Value*
Get(
const Key& key) {
53 if (it ==
entries_.end())
return nullptr;
59 Value*
Peek(
const Key& key) {
61 if (it ==
entries_.end())
return nullptr;
85 void Rename(
const Key& old_key,
const Key& new_key) {
88 Value val = std::move(it->second);
93 lru_.push_back(new_key);
117 template <
typename Fn>
119 for (
auto& [key, value] :
entries_) {
124 template <
typename Fn>
126 for (
const auto& [key, value] :
entries_) {
145 bool evicted =
false;
146 for (
auto it =
lru_.begin(); it !=
lru_.end(); ++it) {
std::map< Key, Value > entries_
void SetEvictionPredicate(EvictionPredicate pred)
EvictionPredicate eviction_predicate_
std::map< Key, Value > & mutable_entries()
void SetCapacity(size_t capacity)
std::function< bool(const Key &)> EvictionPredicate
void ForEach(Fn &&fn) const
Value * Peek(const Key &key)
void RemoveFromLru(const Key &key)
bool Contains(const Key &key) const
Value * Insert(const Key &key, Value value)
void Touch(const Key &key)
const std::map< Key, Value > & entries() const
LruCache(size_t capacity)
bool Erase(const Key &key)
void Rename(const Key &old_key, const Key &new_key)
const std::deque< Key > & lru_order() const
Value * Get(const Key &key)