1 #ifndef UTILITY_FLAT_CHAR_VALUE_MAP_HPP
2 #define UTILITY_FLAT_CHAR_VALUE_MAP_HPP
56 using NumbElementsConsumed = std::size_t;
70 inline const Value*
lookup(
const std::string_view& word,
71 std::size_t& consumed) {
72 const auto numb_elements_consumed = this->
lookup_impl(word);
75 keys_.resize(numb_elements_consumed);
76 values_.resize(numb_elements_consumed);
77 if (numb_elements_consumed == 0) {
80 consumed += numb_elements_consumed;
81 return &values_[numb_elements_consumed - 1];
89 inline void append(
const char key,
const Value& value) {
91 values_.push_back(value);
95 inline void append(
const char key, Value&& value) {
97 values_.push_back(std::move(value));
118 if (keys_.empty() || word.empty())
125 keys_.size() < word.size() ? keys_.size() : word.size();
142 for (; i < shorter; ++i) {
143 if (keys_[i] != word[i])
151 std::vector<Value> values_;
153 mutable std::size_t hits = 0;
154 mutable std::size_t misses = 0;
A small cache for each character of a word and an associated value, such as iterator into a trie for ...
Definition: flat_char_value_map.hpp:30
void append(const char key, Value &&value)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: flat_char_value_map.hpp:95
const Value * lookup(const std::string_view &word, std::size_t &consumed)
Retrieve the cached value for a word.
Definition: flat_char_value_map.hpp:70
void clear()
Clears the cache.
Definition: flat_char_value_map.hpp:101
void append(const char key, const Value &value)
Add a mapping from a char key to value.
Definition: flat_char_value_map.hpp:89
NumbElementsConsumed lookup_impl(const Str &word) const
Lookup word and return how many letters are found in the cache.
Definition: flat_char_value_map.hpp:116
Utility functions.
Definition: flat_char_value_map.hpp:13