Update the cache for a series. Only updates if `ts >= cached_ts`. Returns `true` if the entry was updated (new or newer timestamp).
(&mut self, series_id: SeriesId, ts: i64, value: f64)
| 47 | /// |
| 48 | /// Returns `true` if the entry was updated (new or newer timestamp). |
| 49 | pub fn update(&mut self, series_id: SeriesId, ts: i64, value: f64) -> bool { |
| 50 | match self.entries.get_mut(&series_id) { |
| 51 | Some(entry) if ts >= entry.ts => { |
| 52 | entry.ts = ts; |
| 53 | entry.value = value; |
| 54 | true |
| 55 | } |
| 56 | Some(_) => false, // Older timestamp, skip. |
| 57 | None => { |
| 58 | self.entries.insert(series_id, LastValueEntry { ts, value }); |
| 59 | true |
| 60 | } |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | /// O(1) lookup of the last value for a series. |
| 65 | pub fn get(&self, series_id: SeriesId) -> Option<&LastValueEntry> { |