@@ -115,7 +115,12 @@ where
115
115
}
116
116
117
117
pub trait ArqSpec {
118
+ /// Type of data representing an endomorphism.
119
+ // Note that while a Fn(M) -> M may seem like a more natural representation
120
+ // for an endomorphism, compositions would then have to delegate to each of
121
+ // their parts. This representation is more efficient.
118
122
type F ;
123
+ /// Type of monoid elements.
119
124
type M ;
120
125
/// Require for all f,g,a: apply(compose(f, g), a) = apply(f, apply(g, a))
121
126
fn compose ( f : & Self :: F , g : & Self :: F ) -> Self :: F ;
@@ -129,13 +134,13 @@ pub trait ArqSpec {
129
134
130
135
/// In this example, we want to support range sum queries and range constant
131
136
/// assignments. Note that constant assignment f_c(a) = c is not a endomorphism
132
- /// on integers because f_c(a+b) = c != 2*c = f_c(a) + f_c(b). In intuitive
137
+ /// on (i64, +) because f_c(a+b) = c != 2*c = f_c(a) + f_c(b). In intuitive
133
138
/// terms, the problem is that the internal nodes of the tree should really be
134
139
/// set to a multiple of c, corresponding to the subtree size. So let's augment
135
140
/// the monoid type with size information, using the 2D vector (a_i,1) instead
136
- /// of a_i. Now check that f_c((a, s)) = (c*s, s) is indeed an endomorphism:
137
- /// f_c((a,s)+(b,t)) = f_c((a+b,s+t)) = (c*(s+t),s+t) = (c*s,s)+(c*t,t) =
138
- /// f_c((a,s)) + f_c((b,t)).
141
+ /// of a_i. Now check that f_c((a, s)) = (c*s, s) is indeed an endomorphism on
142
+ /// vector addition: f_c((a,s)+(b,t)) = f_c((a+b,s+t)) = (c*(s+t),s+t)
143
+ /// = (c*s,s)+(c*t,t) = f_c((a,s)) + f_c((b,t)).
139
144
///
140
145
/// # Panics
141
146
///
@@ -186,7 +191,7 @@ impl ArqSpec for AssignMin {
186
191
#[ cfg( test) ]
187
192
mod test {
188
193
use super :: * ;
189
-
194
+
190
195
#[ test]
191
196
fn test_range_sum ( ) {
192
197
let mut arq = ArqTree :: < AssignSum > :: new ( vec ! [ ( 0 , 1 ) ; 10 ] ) ;
@@ -202,7 +207,7 @@ mod test {
202
207
#[ test]
203
208
fn test_rmq ( ) {
204
209
let mut arq = ArqTree :: < AssignMin > :: new ( vec ! [ 0 ; 10 ] ) ;
205
-
210
+
206
211
assert_eq ! ( arq. query( 0 , 9 ) , 0 ) ;
207
212
208
213
arq. modify ( 2 , 4 , & -5 ) ;
0 commit comments