20 #ifndef KERNEL_UTILITIES_LRUCACHE_H 21 #define KERNEL_UTILITIES_LRUCACHE_H 26 #include "pedigree/kernel/processor/types.h" 27 #include "pedigree/kernel/utilities/utility.h" 37 template <
class K,
class T,
size_t Slots = 32>
40 static_assert(Slots >= 4,
"At least four slots are needed for LruCache.");
55 bool get(
const K &key, T &object)
57 for (
size_t i = 0; i < Slots; ++i)
63 else if (m_Slots[i].key != key)
68 object = m_Slots[i].object;
78 void store(
const K &key,
const T &
object)
81 if (m_Slots[0].
set && m_Slots[0].key == key)
86 pedigree_std::copy(&m_Slots[1], &m_Slots[0], Slots - 1);
88 m_Slots[0].object = object;
89 m_Slots[0].set =
true;
111 #endif // KERNEL_UTILITIES_LRUCACHE_H void store(const K &key, const T &object)
LruCache provides a least-recently-used cache abstraction.