@@ -15,15 +15,23 @@ pub trait ArqSpec {
15
15
/// Must satisfy the Identity Law:
16
16
/// For all a, op(a, identity()) = op(identity(), a) = a
17
17
fn identity ( ) -> Self :: S ;
18
- /// For point query / eager updates, compose() can be unimplemented!()
19
- /// For range query / lazy updates, it must satisfy the Composition Law:
18
+ /// Must satisfy the Composition Law:
20
19
/// For all f,g,a, apply(compose(f, g), a) = apply(f, apply(g, a))
21
20
fn compose ( f : & Self :: F , g : & Self :: F ) -> Self :: F ;
22
- /// For point query / eager updates, apply() can assume it acts on a leaf.
23
- /// For range query / lazy updates, it must satisfy the Distributive Law:
24
- /// For all f,a,b, apply(f, op(a, b)) = op(apply(f, a), apply(f, b))
21
+ /// Must satisfy the Distributive Law:
22
+ /// For all f,a,b, apply(f, op(a, b), s+t) = op(apply(f, a, s), apply(f, b, t))
25
23
/// The `size` parameter makes this law easier to satisfy in certain cases.
26
24
fn apply ( f : & Self :: F , a : & Self :: S , size : i64 ) -> Self :: S ;
25
+
26
+ // The following relaxations to the laws may apply.
27
+ // If only point updates are made, the Composition and Distributive Laws
28
+ // no longer apply.
29
+ // - compose() is never called, so it can be left unimplemented!().
30
+ // - apply() is only ever called on leaves, i.e., with size == 1.
31
+ // If only point queries are made, the Associative and Distributive Laws
32
+ // no longer apply.
33
+ // - op()'s result only matters when identity() is an argument.
34
+ // - apply()'s result only matters on leaves, i.e., with size == 1.
27
35
}
28
36
29
37
/// Range Minimum Query (RMQ), a classic application of ARQ.
@@ -109,7 +117,8 @@ impl ArqSpec for SupplyDemand {
109
117
fn compose ( _: & Self :: F , _: & Self :: F ) -> Self :: F {
110
118
unimplemented ! ( )
111
119
}
112
- fn apply ( & ( p_add, o_add) : & Self :: F , & ( p, o, _) : & Self :: S , _: i64 ) -> Self :: S {
120
+ fn apply ( & ( p_add, o_add) : & Self :: F , & ( p, o, _) : & Self :: S , s : i64 ) -> Self :: S {
121
+ assert_eq ! ( s, 1 ) ;
113
122
let p = p + p_add;
114
123
let o = o + o_add;
115
124
( p, o, p. min ( o) )
0 commit comments