1 namespace cachemere::policy {
3 template<
class Key,
class KeyHash,
class Value,
class Cost>
4 EvictionGDSF<Key, KeyHash, Value, Cost>::PriorityEntry::PriorityEntry(KeyRef key,
double coefficient) : m_key(key),
5 m_h_coefficient(coefficient)
9 template<
class Key,
class KeyHash,
class Value,
class Cost>
10 bool EvictionGDSF<Key, KeyHash, Value, Cost>::PriorityEntry::operator<(
const PriorityEntry& other)
const
12 return m_h_coefficient < other.m_h_coefficient;
15 template<
class Key,
class KeyHash,
class Value,
class Cost>
16 EvictionGDSF<Key, KeyHash, Value, Cost>::VictimIterator::VictimIterator(PrioritySetIt iterator) : m_iterator(std::move(iterator))
20 template<
class Key,
class KeyHash,
class Value,
class Cost>
const Key& EvictionGDSF<Key, KeyHash, Value, Cost>::VictimIterator::operator*()
const
22 return m_iterator->m_key;
25 template<
class Key,
class KeyHash,
class Value,
class Cost>
auto EvictionGDSF<Key, KeyHash, Value, Cost>::VictimIterator::operator++() -> VictimIterator&
31 template<
class Key,
class KeyHash,
class Value,
class Cost>
auto EvictionGDSF<Key, KeyHash, Value, Cost>::VictimIterator::operator++(
int) -> VictimIterator
36 template<
class Key,
class KeyHash,
class Value,
class Cost>
37 bool EvictionGDSF<Key, KeyHash, Value, Cost>::VictimIterator::operator==(
const VictimIterator& other)
const
39 return m_iterator == other.m_iterator;
42 template<
class Key,
class KeyHash,
class Value,
class Cost>
43 bool EvictionGDSF<Key, KeyHash, Value, Cost>::VictimIterator::operator!=(
const VictimIterator& other)
const
45 return m_iterator != other.m_iterator;
50 m_priority_set.clear();
51 m_iterator_map.clear();
52 m_frequency_sketch.
clear();
62 m_frequency_sketch.
add(key);
64 PrioritySetIt it = m_priority_set.emplace(std::ref(key), get_h_coefficient(key, item));
65 m_iterator_map[std::ref(key)] = std::move(it);
68 template<
class Key,
class KeyHash,
class Value,
class Cost>
76 auto keyref_and_it = m_iterator_map.find(std::ref(key));
77 assert(keyref_and_it != m_iterator_map.end());
79 PrioritySetIt it = keyref_and_it->second;
81 m_priority_set.erase(it);
88 auto keyref_and_it = m_iterator_map.find(std::ref(key));
89 assert(keyref_and_it != m_iterator_map.end());
91 PrioritySetIt it = keyref_and_it->second;
92 m_clock = std::max(m_clock,
static_cast<uint64_t
>(it->m_h_coefficient));
94 m_priority_set.erase(it);
95 m_iterator_map.erase(keyref_and_it);
97 assert(m_iterator_map.find(key) == m_iterator_map.end());
110 template<
class Key,
class KeyHash,
class Value,
class Cost>
113 return static_cast<double>(m_clock) +
114 static_cast<double>(m_frequency_sketch.
estimate(key)) * (
static_cast<double>(m_measure_cost(key, item)) /
static_cast<double>(item.m_total_size));