Insert or update a key-value pair
| 60 | |
| 61 | // Insert or update a key-value pair |
| 62 | void insert(const Key &key, const T &value) { |
| 63 | // Only evict if we're at capacity AND this is a new key |
| 64 | const ValueWithTimestamp *existing = mMap.find_value(key); |
| 65 | |
| 66 | auto curr = mCurrentTime++; |
| 67 | |
| 68 | if (existing) { |
| 69 | // Update the value and access time |
| 70 | ValueWithTimestamp &vwt = |
| 71 | const_cast<ValueWithTimestamp &>(*existing); |
| 72 | vwt.value = value; |
| 73 | vwt.last_access_time = curr; |
| 74 | return; |
| 75 | } |
| 76 | if (mMap.size() >= mMaxSize) { |
| 77 | evictOldest(); |
| 78 | } |
| 79 | |
| 80 | // Insert or update the value with current timestamp |
| 81 | ValueWithTimestamp vwt(value, mCurrentTime); |
| 82 | mMap.insert(key, vwt); |
| 83 | } |
| 84 | |
| 85 | // Get value for key, returns nullptr if not found |
| 86 | T *find_value(const Key &key) { |
nothing calls this directly
no test coverage detected