Skip to content

Commit 2ba30de

Browse files
Add a template util to help create a lazy_segment_tree
1 parent 7fe88db commit 2ba30de

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

library/mrpython/lazy_segment_tree.hpp

+25
Original file line numberDiff line numberDiff line change
@@ -122,5 +122,30 @@ using lazy_segment_tree_add_add =
122122
lazy_segment_tree<T, std::plus<T>, T,
123123
lazy_segment_tree_add_add_operate_function<T>,
124124
std::plus<T>>;
125+
126+
template <typename NodeStruct> class lazy_segment_tree_from_node {
127+
using T = typename NodeStruct::T;
128+
using Lazy = typename NodeStruct::Lazy;
129+
struct MergeFunction {
130+
T operator()(T const& a, T const& b) const {
131+
return NodeStruct::merge_data(a, b);
132+
}
133+
};
134+
struct OperateFunction {
135+
T operator()(Lazy const& lazy, T const& data, size_t size) const {
136+
return NodeStruct::operate(lazy, data, size);
137+
}
138+
};
139+
struct MergeLazyFunction {
140+
Lazy operator()(Lazy const& a, Lazy const& b) const {
141+
return NodeStruct::merge_lazy(a, b);
142+
}
143+
};
144+
lazy_segment_tree_from_node() = delete;
145+
146+
public:
147+
using type = lazy_segment_tree<T, MergeFunction, Lazy, OperateFunction,
148+
MergeLazyFunction>;
149+
};
125150
} // namespace mrpython
126151
#endif

0 commit comments

Comments
 (0)