Skip to content

Commit dc1c6b7

Browse files
Changed Copy to Clone
1 parent 6a6259f commit dc1c6b7

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/segtree.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::marker::PhantomData;
55

66
// TODO Should I split monoid-related traits to another module?
77
pub trait Monoid {
8-
type S: Copy;
8+
type S: Clone;
99
fn identity() -> Self::S;
1010
fn binary_operation(a: Self::S, b: Self::S) -> Self::S;
1111
}
@@ -63,7 +63,7 @@ impl<M: Monoid> Segtree<M> {
6363

6464
pub fn get(&self, p: usize) -> M::S {
6565
assert!(p < self.n);
66-
self.d[p + self.size]
66+
self.d[p + self.size].clone()
6767
}
6868

6969
pub fn prod(&self, mut l: usize, mut r: usize) -> M::S {
@@ -75,12 +75,12 @@ impl<M: Monoid> Segtree<M> {
7575

7676
while l < r {
7777
if l & 1 != 0 {
78-
sml = M::binary_operation(sml, self.d[l]);
78+
sml = M::binary_operation(sml, self.d[l].clone());
7979
l += 1;
8080
}
8181
if r & 1 != 0 {
8282
r -= 1;
83-
smr = M::binary_operation(self.d[r], smr);
83+
smr = M::binary_operation(self.d[r].clone(), smr);
8484
}
8585
l >>= 1;
8686
r >>= 1;
@@ -90,7 +90,7 @@ impl<M: Monoid> Segtree<M> {
9090
}
9191

9292
pub fn all_prod(&self) -> M::S {
93-
self.d[1]
93+
self.d[1].clone()
9494
}
9595

9696
pub fn max_right<F>(&self, mut l: usize, f: F) -> usize
@@ -109,18 +109,18 @@ impl<M: Monoid> Segtree<M> {
109109
while l % 2 == 0 {
110110
l >>= 1;
111111
}
112-
if !f(M::binary_operation(sm, self.d[l])) {
112+
if !f(M::binary_operation(sm.clone(), self.d[l].clone())) {
113113
while l < self.size {
114114
l *= 2;
115-
let res = M::binary_operation(sm, self.d[l]);
116-
if f(res) {
115+
let res = M::binary_operation(sm.clone(), self.d[l].clone());
116+
if f(res.clone()) {
117117
sm = res;
118118
l += 1;
119119
}
120120
}
121121
return l - self.size;
122122
}
123-
sm = M::binary_operation(sm, self.d[l]);
123+
sm = M::binary_operation(sm.clone(), self.d[l].clone());
124124
l += 1;
125125
// while
126126
{
@@ -148,18 +148,18 @@ impl<M: Monoid> Segtree<M> {
148148
while r > 1 && r % 2 == 1 {
149149
r >>= 1;
150150
}
151-
if !f(M::binary_operation(self.d[r], sm)) {
151+
if !f(M::binary_operation(self.d[r].clone(), sm.clone())) {
152152
while r < self.size {
153153
r = 2 * r + 1;
154-
let res = M::binary_operation(self.d[r], sm);
155-
if f(res) {
154+
let res = M::binary_operation(self.d[r].clone(), sm.clone());
155+
if f(res.clone()) {
156156
sm = res;
157157
r -= 1;
158158
}
159159
}
160160
return r + 1 - self.size;
161161
}
162-
sm = M::binary_operation(self.d[r], sm);
162+
sm = M::binary_operation(self.d[r].clone(), sm.clone());
163163
// while
164164
{
165165
let r = r as isize;
@@ -170,7 +170,7 @@ impl<M: Monoid> Segtree<M> {
170170
}
171171

172172
fn update(&mut self, k: usize) {
173-
self.d[k] = M::binary_operation(self.d[2 * k], self.d[2 * k + 1]);
173+
self.d[k] = M::binary_operation(self.d[2 * k].clone(), self.d[2 * k + 1].clone());
174174
}
175175
}
176176

0 commit comments

Comments
 (0)