From e9958381801bf44fd0635aaa1e68541b21e193e0 Mon Sep 17 00:00:00 2001 From: Gloria Mundi Date: Fri, 15 Mar 2024 01:48:00 +0100 Subject: fix persistent and add test --- Makefile | 3 +++ datastructures/persistent.cpp | 2 +- datastructures/test/persistent.cpp | 10 ++++++++++ 3 files changed, 14 insertions(+), 1 deletion(-) create mode 100644 datastructures/test/persistent.cpp diff --git a/Makefile b/Makefile index 39f92b0..7c0916a 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,7 @@ TESTS = \ datastructures/test/fenwickTree.test \ datastructures/test/fenwickTree2.test \ datastructures/test/monotonicConvexHull.test \ + datastructures/test/persistent.test \ graph/test/binary_lifting.test \ graph/test/LCA_sparse.test @@ -43,6 +44,8 @@ datastructures/test/fenwickTree2.test: datastructures/test/fenwickTree2.cpp \ datastructures/test/monotonicConvexHull.test: \ datastructures/test/monotonicConvexHull.cpp \ datastructures/monotonicConvexHull.cpp +datastructures/test/persistent.test: datastructures/test/persistent.cpp \ + datastructures/persistent.cpp graph/test/binary_lifting.test: graph/test/binary_lifting.cpp \ graph/binary_lifting.cpp graph/test/util.cpp graph/test/LCA_sparse.test: graph/test/LCA_sparse.cpp \ diff --git a/datastructures/persistent.cpp b/datastructures/persistent.cpp index 0a65a79..4093cdc 100644 --- a/datastructures/persistent.cpp +++ b/datastructures/persistent.cpp @@ -7,7 +7,7 @@ struct persistent { : time(time), data(1, {time, value}) {} T get(int t) { - return prev(upper_bound(all(data), {t+1, {}}))->second; + return prev(upper_bound(all(data), pair{t+1, T{}}))->second; } int set(T value) { diff --git a/datastructures/test/persistent.cpp b/datastructures/test/persistent.cpp new file mode 100644 index 0000000..d98569b --- /dev/null +++ b/datastructures/test/persistent.cpp @@ -0,0 +1,10 @@ +#include "../persistent.cpp" + +int main() { + int time = 0; + persistent p(time, 0); + p.set(1); + int t1 = time; + p.set(2); + assert(p.get(t1) == 1); +} -- cgit v1.2.3