diff --git a/dogsdogsdogs/src/calculus.rs b/dogsdogsdogs/src/calculus.rs index 16546f226..952a1b0d2 100644 --- a/dogsdogsdogs/src/calculus.rs +++ b/dogsdogsdogs/src/calculus.rs @@ -41,7 +41,9 @@ where self.enter(child) .inner .flat_map(|(data, time, diff)| { - let neu = (data.clone(), AltNeu::neu(time.time.clone()), diff.clone().negate()); + let mut neg_diff = diff.clone(); + neg_diff.negate(); + let neu = (data.clone(), AltNeu::neu(time.time.clone()), neg_diff); let alt = (data, time, diff); Some(alt).into_iter().chain(Some(neu)) }) diff --git a/src/algorithms/identifiers.rs b/src/algorithms/identifiers.rs index 8864ba89d..19653d8d3 100644 --- a/src/algorithms/identifiers.rs +++ b/src/algorithms/identifiers.rs @@ -67,12 +67,16 @@ where // keep round-positive records as changes. let ((round, record), count) = &input[0]; if *round > 0 { - output.push(((0, record.clone()), count.clone().negate())); + let mut neg_count = count.clone(); + neg_count.negate(); + output.push(((0, record.clone()), neg_count)); output.push(((*round, record.clone()), count.clone())); } // if any losers, increment their rounds. for ((round, record), count) in input[1..].iter() { - output.push(((0, record.clone()), count.clone().negate())); + let mut neg_count = count.clone(); + neg_count.negate(); + output.push(((0, record.clone()), neg_count)); output.push(((*round+1, record.clone()), count.clone())); } }) diff --git a/src/collection.rs b/src/collection.rs index ce2dd54a9..ddf3634cb 100644 --- a/src/collection.rs +++ b/src/collection.rs @@ -549,7 +549,7 @@ impl Collection where G::Timesta /// ``` pub fn negate(&self) -> Collection { self.inner - .map_in_place(|x| x.2 = x.2.clone().negate()) + .map_in_place(|x| x.2.negate()) .as_collection() } diff --git a/src/difference.rs b/src/difference.rs index 42c7bfe44..71c724905 100644 --- a/src/difference.rs +++ b/src/difference.rs @@ -62,7 +62,7 @@ pub trait Monoid : Semigroup { /// not quite as many as you might imagine. pub trait Abelian : Monoid { /// The method of `std::ops::Neg`, for types that do not implement `Neg`. - fn negate(self) -> Self; + fn negate(&mut self); } /// A replacement for `std::ops::Mul` for types that do not implement it. @@ -97,7 +97,7 @@ macro_rules! builtin_implementation { macro_rules! builtin_abelian_implementation { ($t:ty) => { impl Abelian for $t { - #[inline] fn negate(self) -> Self { -self } + #[inline] fn negate(&mut self) { *self = -*self; } } }; } @@ -137,7 +137,7 @@ macro_rules! wrapping_implementation { } impl Abelian for $t { - #[inline] fn negate(self) -> Self { -self } + #[inline] fn negate(&mut self) { *self = -*self; } } impl Multiply for $t { @@ -225,9 +225,9 @@ mod tuples { impl<$($name: Abelian),*> Abelian for ($($name,)*) { #[allow(non_snake_case)] - #[inline] fn negate(self) -> Self { - let ($($name,)*) = self; - ( $($name.negate(), )* ) + #[inline] fn negate(&mut self) { + let ($(ref mut $name,)*) = self; + $($name.negate();)* } } @@ -301,11 +301,10 @@ mod vector { } impl Abelian for Vec { - fn negate(mut self) -> Self { + fn negate(&mut self) { for update in self.iter_mut() { - *update = update.clone().negate(); + update.negate(); } - self } } diff --git a/src/operators/arrange/arrangement.rs b/src/operators/arrange/arrangement.rs index ac08382c7..370d085a6 100644 --- a/src/operators/arrange/arrangement.rs +++ b/src/operators/arrange/arrangement.rs @@ -305,7 +305,7 @@ where if !input.is_empty() { logic(key, input, change); } - change.extend(output.drain(..).map(|(x,d)| (x, d.negate()))); + change.extend(output.drain(..).map(|(x,mut d)| { d.negate(); (x, d) })); crate::consolidation::consolidate(change); }) } diff --git a/src/operators/reduce.rs b/src/operators/reduce.rs index e15e15eff..580260575 100644 --- a/src/operators/reduce.rs +++ b/src/operators/reduce.rs @@ -266,7 +266,7 @@ pub trait ReduceCore where if !input.is_empty() { logic(key, input, change); } - change.extend(output.drain(..).map(|(x,d)| (x, d.negate()))); + change.extend(output.drain(..).map(|(x,mut d)| { d.negate(); (x, d) })); crate::consolidation::consolidate(change); }) } diff --git a/src/operators/threshold.rs b/src/operators/threshold.rs index 8e8548ece..3d8a405a2 100644 --- a/src/operators/threshold.rs +++ b/src/operators/threshold.rs @@ -43,7 +43,11 @@ pub trait ThresholdTotal w fn threshold_totalR2+'static>(&self, mut thresh: F) -> Collection { self.threshold_semigroup(move |key, new, old| { let mut new = thresh(key, new); - if let Some(old) = old { new.plus_equals(&thresh(key, old).negate()); } + if let Some(old) = old { + let mut add = thresh(key, old); + add.negate(); + new.plus_equals(&add); + } if !new.is_zero() { Some(new) } else { None } }) }