| 67 | }; |
| 68 | |
| 69 | void set(const T& value, const Time& time = Clock::now()) |
| 70 | { |
| 71 | // If we're not inserting at the end of the time series, then |
| 72 | // we have to reset the sparsification index. Given that |
| 73 | // out-of-order insertion is a rare use-case. This is a simple way |
| 74 | // to keep insertions O(log(n)). No need to figure out how to |
| 75 | // adjust the truncation index. |
| 76 | if (!values.empty() && time < values.rbegin()->first) { |
| 77 | index = None(); |
| 78 | } |
| 79 | |
| 80 | values[time] = value; |
| 81 | truncate(); |
| 82 | sparsify(); |
| 83 | } |
| 84 | |
| 85 | // Returns the time series within the (optional) time range. |
| 86 | std::vector<Value> get( |