diff options
| author | mzuenni <michi.zuendorf@gmail.com> | 2022-06-27 17:19:28 +0200 |
|---|---|---|
| committer | mzuenni <michi.zuendorf@gmail.com> | 2022-06-27 17:19:28 +0200 |
| commit | 5ab8a5088b729a9953b8dff1b2a985dc8fb2098b (patch) | |
| tree | ed40d6936c0e9eee40ba62751cbf99ecddbaddc2 /datastructures/persistent.cpp | |
| parent | adabbad9c51cf7cd3874bfde8eac1fbcf84fec10 (diff) | |
updated tcr
Diffstat (limited to 'datastructures/persistent.cpp')
| -rw-r--r-- | datastructures/persistent.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/datastructures/persistent.cpp b/datastructures/persistent.cpp new file mode 100644 index 0000000..befecf7 --- /dev/null +++ b/datastructures/persistent.cpp @@ -0,0 +1,19 @@ +template<typename T>
+struct persistent {
+ int& time;
+ vector<pair<int, T>> data;
+
+ persistent(int& time, T value = {})
+ : time(time), data(1, {time, value}) {}
+
+ T get(int t) {
+ return prev(upper_bound(all(data),
+ pair<int, T>(t+1, {})))->second;
+ }
+
+ int set(T value) {
+ time+=2;
+ data.push_back({time, value});
+ return time;
+ }
+};
|
