| 47 | } |
| 48 | |
| 49 | void put(Key key, Value value) { |
| 50 | if (capacity_ == 0) { |
| 51 | entries_.clear(); |
| 52 | return; |
| 53 | } |
| 54 | for (auto & entry : entries_) { |
| 55 | if (equal_(entry.key, key)) { |
| 56 | entry.key = std::move(key); |
| 57 | entry.value = std::move(value); |
| 58 | entry.last_used = next_tick(); |
| 59 | return; |
| 60 | } |
| 61 | } |
| 62 | if (entries_.size() >= capacity_) { |
| 63 | erase_lru(); |
| 64 | } |
| 65 | entries_.push_back(Entry{ |
| 66 | std::move(key), |
| 67 | std::move(value), |
| 68 | next_tick(), |
| 69 | }); |
| 70 | } |
| 71 | |
| 72 | template <typename Fn> |
| 73 | void for_each_value(Fn && fn) { |