50template <
typename CharType,
typename Value>
76 if (it ==
m_map.end()) {
80 const size_t matched_len = it->first.size();
82 buffer.remove_prefix(matched_len);
84 return &it->second.value;
103 if (
m_map.contains(prefix)) {
107 auto [it, inserted] =
116 if (it !=
m_map.begin()) {
123 if (next !=
m_map.end()) {
139 using Map = std::map<sequence, Entry, std::greater<>>;
140 using It =
typename Map::iterator;
142 using Lru_it =
typename Lru_list::iterator;
166 it->second.lru_pos =
m_lru.begin();
170 m_lru.push_front(it);
171 it->second.lru_pos =
m_lru.begin();
Definition: mock_resolver.h:43
void * data() const noexcept
Definition: buffer.h:119
size_t size() const noexcept
Definition: buffer.h:120
Bounded cache for prefix lookups with MRU/LRU recency tracking.
Definition: ut0prefix_cache.h:51
bool insert(sequence_view prefix, Value value)
Insert a new prefix/value pair as the most recently used entry.
Definition: ut0prefix_cache.h:102
std::list< It > Lru_list
Definition: ut0prefix_cache.h:141
std::basic_string< CharType > sequence
Definition: ut0prefix_cache.h:53
prefix_cache(const prefix_cache &)=delete
prefix_cache & operator=(const prefix_cache &)=delete
Value * find_value_for_prefix_of(sequence_view &buffer)
Find a cached value whose key is the longest prefix of buffer.
Definition: ut0prefix_cache.h:74
std::map< sequence, Entry, std::greater<> > Map
Definition: ut0prefix_cache.h:139
It try_find(sequence_view buffer)
Definition: ut0prefix_cache.h:155
static bool is_prefix(sequence_view key, sequence_view buffer)
Definition: ut0prefix_cache.h:149
typename Lru_list::iterator Lru_it
Definition: ut0prefix_cache.h:142
Lru_list m_lru
Definition: ut0prefix_cache.h:186
void move_to_front(It it)
Definition: ut0prefix_cache.h:163
size_t m_capacity
Definition: ut0prefix_cache.h:184
Map m_map
Definition: ut0prefix_cache.h:185
void link_new_mru(It it)
Definition: ut0prefix_cache.h:169
std::basic_string_view< CharType > sequence_view
Definition: ut0prefix_cache.h:54
prefix_cache(size_t capacity)
Create a cache with at most capacity stored prefixes.
Definition: ut0prefix_cache.h:59
typename Map::iterator It
Definition: ut0prefix_cache.h:140
void enforce_capacity()
Definition: ut0prefix_cache.h:174
ValueType value(const std::optional< ValueType > &v)
Definition: gtid.h:83
mutable_buffer buffer(void *p, size_t n) noexcept
Definition: buffer.h:418
This file contains a set of libraries providing overloads for regular dynamic allocation routines whi...
Definition: aligned_alloc.h:48
required string key
Definition: replication_asynchronous_connection_failover.proto:60
static int compare(size_t a, size_t b)
Function to compare two size_t integers for their relative order.
Definition: rpl_utility.cc:114
Definition: ut0prefix_cache.h:144
Value value
Definition: ut0prefix_cache.h:145
Lru_it lru_pos
Definition: ut0prefix_cache.h:146
Version control for database, common definitions, and include files.
#define ut_ad(EXPR)
Debug assertion.
Definition: ut0dbg.h:109
#define ut_a(EXPR)
Abort execution if EXPR does not evaluate to nonzero.
Definition: ut0dbg.h:97