yaze 0.3.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
yaze::util::LruCache< Key, Value > Class Template Reference

#include <lru_cache.h>

Inheritance diagram for yaze::util::LruCache< Key, Value >:

Public Types

using EvictionPredicate = std::function<bool(const Key&)>
 

Public Member Functions

 LruCache (size_t capacity)
 
Value * Insert (const Key &key, Value value)
 
Value * Get (const Key &key)
 
Value * Peek (const Key &key)
 
bool Contains (const Key &key) const
 
void Touch (const Key &key)
 
bool Erase (const Key &key)
 
void Rename (const Key &old_key, const Key &new_key)
 
void Clear ()
 
size_t Size () const
 
size_t Capacity () const
 
bool Empty () const
 
void SetCapacity (size_t capacity)
 
void SetEvictionPredicate (EvictionPredicate pred)
 
template<typename Fn >
void ForEach (Fn &&fn)
 
template<typename Fn >
void ForEach (Fn &&fn) const
 
const std::map< Key, Value > & entries () const
 
std::map< Key, Value > & mutable_entries ()
 
const std::deque< Key > & lru_order () const
 

Private Member Functions

void RemoveFromLru (const Key &key)
 
void EvictIfNeeded ()
 

Private Attributes

size_t capacity_
 
std::map< Key, Value > entries_
 
std::deque< Key > lru_
 
EvictionPredicate eviction_predicate_
 

Detailed Description

template<typename Key, typename Value>
class yaze::util::LruCache< Key, Value >

Definition at line 33 of file lru_cache.h.

Member Typedef Documentation

◆ EvictionPredicate

template<typename Key , typename Value >
using yaze::util::LruCache< Key, Value >::EvictionPredicate = std::function<bool(const Key&)>

Definition at line 35 of file lru_cache.h.

Constructor & Destructor Documentation

◆ LruCache()

template<typename Key , typename Value >
yaze::util::LruCache< Key, Value >::LruCache ( size_t capacity)
inlineexplicit

Definition at line 37 of file lru_cache.h.

Member Function Documentation

◆ Insert()

template<typename Key , typename Value >
Value * yaze::util::LruCache< Key, Value >::Insert ( const Key & key,
Value value )
inline

◆ Get()

template<typename Key , typename Value >
Value * yaze::util::LruCache< Key, Value >::Get ( const Key & key)
inline

Definition at line 51 of file lru_cache.h.

References yaze::util::LruCache< Key, Value >::entries_, and yaze::util::LruCache< Key, Value >::Touch().

Here is the call graph for this function:

◆ Peek()

template<typename Key , typename Value >
Value * yaze::util::LruCache< Key, Value >::Peek ( const Key & key)
inline

Definition at line 59 of file lru_cache.h.

References yaze::util::LruCache< Key, Value >::entries_.

◆ Contains()

template<typename Key , typename Value >
bool yaze::util::LruCache< Key, Value >::Contains ( const Key & key) const
inline

Definition at line 66 of file lru_cache.h.

References yaze::util::LruCache< Key, Value >::entries_.

◆ Touch()

template<typename Key , typename Value >
void yaze::util::LruCache< Key, Value >::Touch ( const Key & key)
inline

Definition at line 71 of file lru_cache.h.

References yaze::util::LruCache< Key, Value >::lru_, and yaze::util::LruCache< Key, Value >::RemoveFromLru().

Referenced by yaze::util::LruCache< Key, Value >::Get().

Here is the call graph for this function:

◆ Erase()

template<typename Key , typename Value >
bool yaze::util::LruCache< Key, Value >::Erase ( const Key & key)
inline

◆ Rename()

template<typename Key , typename Value >
void yaze::util::LruCache< Key, Value >::Rename ( const Key & old_key,
const Key & new_key )
inline

◆ Clear()

template<typename Key , typename Value >
void yaze::util::LruCache< Key, Value >::Clear ( )
inline

◆ Size()

template<typename Key , typename Value >
size_t yaze::util::LruCache< Key, Value >::Size ( ) const
inline

Definition at line 101 of file lru_cache.h.

References yaze::util::LruCache< Key, Value >::entries_.

◆ Capacity()

template<typename Key , typename Value >
size_t yaze::util::LruCache< Key, Value >::Capacity ( ) const
inline

Definition at line 102 of file lru_cache.h.

References yaze::util::LruCache< Key, Value >::capacity_.

◆ Empty()

template<typename Key , typename Value >
bool yaze::util::LruCache< Key, Value >::Empty ( ) const
inline

Definition at line 103 of file lru_cache.h.

References yaze::util::LruCache< Key, Value >::entries_.

◆ SetCapacity()

template<typename Key , typename Value >
void yaze::util::LruCache< Key, Value >::SetCapacity ( size_t capacity)
inline

Definition at line 105 of file lru_cache.h.

References yaze::util::LruCache< Key, Value >::capacity_, and yaze::util::LruCache< Key, Value >::EvictIfNeeded().

Here is the call graph for this function:

◆ SetEvictionPredicate()

template<typename Key , typename Value >
void yaze::util::LruCache< Key, Value >::SetEvictionPredicate ( EvictionPredicate pred)
inline

◆ ForEach() [1/2]

template<typename Key , typename Value >
template<typename Fn >
void yaze::util::LruCache< Key, Value >::ForEach ( Fn && fn)
inline

Definition at line 118 of file lru_cache.h.

References yaze::util::LruCache< Key, Value >::entries_.

◆ ForEach() [2/2]

template<typename Key , typename Value >
template<typename Fn >
void yaze::util::LruCache< Key, Value >::ForEach ( Fn && fn) const
inline

Definition at line 125 of file lru_cache.h.

References yaze::util::LruCache< Key, Value >::entries_.

◆ entries()

template<typename Key , typename Value >
const std::map< Key, Value > & yaze::util::LruCache< Key, Value >::entries ( ) const
inline

Definition at line 132 of file lru_cache.h.

References yaze::util::LruCache< Key, Value >::entries_.

◆ mutable_entries()

template<typename Key , typename Value >
std::map< Key, Value > & yaze::util::LruCache< Key, Value >::mutable_entries ( )
inline

Definition at line 133 of file lru_cache.h.

References yaze::util::LruCache< Key, Value >::entries_.

◆ lru_order()

template<typename Key , typename Value >
const std::deque< Key > & yaze::util::LruCache< Key, Value >::lru_order ( ) const
inline

Definition at line 136 of file lru_cache.h.

References yaze::util::LruCache< Key, Value >::lru_.

◆ RemoveFromLru()

template<typename Key , typename Value >
void yaze::util::LruCache< Key, Value >::RemoveFromLru ( const Key & key)
inlineprivate

◆ EvictIfNeeded()

Member Data Documentation

◆ capacity_

template<typename Key , typename Value >
size_t yaze::util::LruCache< Key, Value >::capacity_
private

◆ entries_

◆ lru_

◆ eviction_predicate_

template<typename Key , typename Value >
EvictionPredicate yaze::util::LruCache< Key, Value >::eviction_predicate_
private

The documentation for this class was generated from the following file: