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/persistentArray.cpp | |
| parent | adabbad9c51cf7cd3874bfde8eac1fbcf84fec10 (diff) | |
updated tcr
Diffstat (limited to 'datastructures/persistentArray.cpp')
| -rw-r--r-- | datastructures/persistentArray.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/datastructures/persistentArray.cpp b/datastructures/persistentArray.cpp new file mode 100644 index 0000000..665d908 --- /dev/null +++ b/datastructures/persistentArray.cpp @@ -0,0 +1,26 @@ +template<typename T>
+struct persistentArray{
+ int time = 0;
+ vector<persistent<T>> data;
+ vector<pair<int, int>> mods;
+
+ persistentArray(int n, T value = {})
+ : time(0), data(n, {time, value}) {}
+
+ T get(int p, int t) {
+ return data[p].get(t);
+ }
+
+ int set(int p, T value) {
+ mods.push_back({p, time});
+ return data[p].set(value);
+ }
+
+ void reset(int t) {
+ while (!mods.empty() && mods.back().second > t) {
+ data[mods.back().first].data.pop_back();
+ mods.pop_back();
+ }
+ time = t;
+ }
+};
\ No newline at end of file |
