summaryrefslogtreecommitdiff
path: root/datastructures/test/lazyPropagation.awk
diff options
context:
space:
mode:
authorGloria Mundi <gloria@gloria-mundi.eu>2024-05-01 21:25:26 +0200
committerGloria Mundi <gloria@gloria-mundi.eu>2024-05-01 21:25:26 +0200
commite0beaa56b648367bc52dc8c7d44162ac1c8b45fe (patch)
tree8320be6afe8953e1cf4cc98b00ba87e1ba66e58a /datastructures/test/lazyPropagation.awk
parent5e012c297016f928260b9a4cb00b24de2d415df9 (diff)
slightly simplify lazy propagation and add tests
Diffstat (limited to 'datastructures/test/lazyPropagation.awk')
-rw-r--r--datastructures/test/lazyPropagation.awk86
1 files changed, 86 insertions, 0 deletions
diff --git a/datastructures/test/lazyPropagation.awk b/datastructures/test/lazyPropagation.awk
new file mode 100644
index 0000000..fc39305
--- /dev/null
+++ b/datastructures/test/lazyPropagation.awk
@@ -0,0 +1,86 @@
+
+/Neutral element for combine/ {
+ print "#ifndef SEGTREE_FIRST_NEG"
+ print "# ifndef SEGTREE_MAX"
+ print
+ print "# else"
+ tmp = $0
+ sub(/0/, "numeric_limits<T>::min()", tmp)
+ print tmp
+ print "# endif"
+ print "#else"
+ sub(/0/, "numeric_limits<T>::max()")
+ print
+ print "#endif"
+ next
+}
+
+/Modify this \+ E/ {
+ print "#ifndef SEGTREE_FIRST_NEG"
+ print "# ifndef SEGTREE_MAX"
+ print
+ print "# else"
+ tmp = $0
+ sub(/a \+ b/, "max(a, b)", tmp)
+ print tmp
+ print "# endif"
+ print "#else"
+ sub(/a \+ b/, "a < 0 ? a : min(a, b)")
+ print
+ print "#endif"
+ next
+}
+
+/Unused value by updates/ {
+ print "#ifndef SEGTREE_FIRST_NEG"
+ print
+ print "#else"
+ sub(/0/, /numeric_limits<U>::max()/)
+ print
+ print "#endif"
+ next
+}
+
+/And this \+ UF/ {
+ print
+ getline set_tree
+ getline set_lazy
+ print "#ifndef SEGTREE_MAX"
+ print "# ifndef SEGTREE_FIRST_NEG"
+ print set_tree
+ print "# else"
+ tmp = set_tree
+ sub(/val \* k\[i\]/, "val", tmp)
+ print tmp
+ print "# endif"
+ print set_lazy
+ print "#else"
+ sub(/= val \* k\[i\]/, "+= val", set_tree)
+ sub(/= val/, "+= val", set_lazy)
+ print set_tree
+ print set_lazy
+ print "#endif"
+ next
+}
+
+/Optional/ { print "#ifdef SEGTREE_MAX" }
+/^\};$/ { print "#endif" }
+
+/SegTree\(const vector<T>& a\)/ {
+ print "#ifndef SEGTREE_INIT_DEFAULT"
+ print
+ print "#else"
+ getline
+ sub(/\/\//, "")
+ print
+ print "#endif"
+ getline
+ print
+ print "#ifndef SEGTREE_INIT_DEFAULT"
+ getline
+ print
+ print "#endif"
+ next
+}
+
+{ print }