1#ifndef TATOOINE_CACHE_H
2#define TATOOINE_CACHE_H
12template <
typename Key,
typename Value>
35 cache(uint64_t max_elements = std::numeric_limits<uint64_t>::max(),
36 uint64_t max_memory_usage = std::numeric_limits<uint64_t>::max())
87 auto insert(
const Key& key,
const Value& value) {
88 auto insertion =
m_data.insert(std::pair{key, value});
89 enqueue(insertion.first, insertion.second);
93 auto insert(Key&& key,
const Value& value) {
94 auto insertion =
m_data.insert(std::pair{std::move(key), value});
95 enqueue(insertion.first, insertion.second);
99 auto insert(
const Key& key, Value&& value) {
100 auto insertion =
m_data.insert(std::pair{key, std::move(value)});
101 enqueue(insertion.first, insertion.second);
106 auto insertion =
m_data.insert(std::pair{std::move(key), std::move(value)});
107 enqueue(insertion.first, insertion.second);
111 template <
typename... Args>
112 auto emplace(
const Key& key, Args&&... args) {
113 return insert(key, Value{std::forward<Args>(args)...});
120 const auto&
at(
const Key& key)
const {
121 auto it =
m_data.find(key);
126 auto&
at(
const Key& key) {
127 auto it =
m_data.find(key);
132 std::optional<const_iterator>
contains(
const Key& key)
const {
auto & operator[](const Key &key)
Definition: cache.h:118
cache(const cache &other)
Definition: cache.h:38
cache(cache &&other)=default
void capacity_check()
Definition: cache.h:63
void clear()
Definition: cache.h:145
auto insert(const Key &key, Value &&value)
Definition: cache.h:99
auto size() const
Definition: cache.h:143
cache(uint64_t max_elements=std::numeric_limits< uint64_t >::max(), uint64_t max_memory_usage=std::numeric_limits< uint64_t >::max())
Definition: cache.h:35
std::map< Key, Value > container_type
Definition: cache.h:18
const auto & operator[](const Key &key) const
Definition: cache.h:116
const auto & at(const Key &key) const
Definition: cache.h:120
auto emplace(const Key &key, Args &&... args)
Definition: cache.h:112
auto insert(Key &&key, Value &&value)
Definition: cache.h:105
bool is_cached(const Key &key) const
Definition: cache.h:139
void enqueue(const_iterator it, bool ins)
Definition: cache.h:73
cache & operator=(cache &&other)=default
auto & operator=(const cache &other)
Definition: cache.h:48
typename container_type::const_iterator const_iterator
Definition: cache.h:19
void refresh_usage(const_iterator it)
Definition: cache.h:80
auto & at(const Key &key)
Definition: cache.h:126
uint64_t m_max_memory_usage
Definition: cache.h:29
std::list< const_iterator > usage_type
Definition: cache.h:20
auto insert(const Key &key, const Value &value)
Definition: cache.h:87
auto insert(Key &&key, const Value &value)
Definition: cache.h:93
container_type m_data
Definition: cache.h:26
std::optional< const_iterator > contains(const Key &key) const
Definition: cache.h:132
usage_type m_usage
Definition: cache.h:27
uint64_t m_max_elements
Definition: cache.h:28
Definition: algorithm.h:6
constexpr auto distance(Iter const &it0, Iter const &it1)
Definition: iterator_facade.h:372
auto begin(Range &&range)
Definition: iterator_facade.h:318
auto end(Range &&range)
Definition: iterator_facade.h:322
auto next(Iter iter)
Definition: iterator_facade.h:325