10 cache_map_.add_overwrite(*key, std::move(value));
11 keys_.append(std::move(key));
16 std::unique_ptr<Value> *value = cache_map_.lookup_ptr(key);
17 if (value ==
nullptr) {
20 const Key &stored_cache_key = cache_map_.lookup_key(key);
21 stored_cache_key.
is_used =
true;
26 std::unique_ptr<Key> key,
FunctionRef<std::unique_ptr<Value>()> create_value)
29 if (value !=
nullptr) {
32 std::unique_ptr<Value> new_value = create_value();
33 value = new_value.get();
34 this->
add(std::move(key), std::move(new_value));
40 for (std::unique_ptr<Key> &key : keys_) {
48 for (
auto it = cache_map_.keys().begin(); it != cache_map_.keys().end(); ++it) {
51 cache_map_.remove(it);
55 for (
int i = 0; i < keys_.size();) {
56 if (keys_[i]->is_used) {
60 keys_.remove_and_reorder(i);
Value * lookup(const Key &key)
void add(std::unique_ptr< Key > key, std::unique_ptr< Value > value)
Value & lookup_or_add(std::unique_ptr< Key > key, FunctionRef< std::unique_ptr< Value >()> create_value)