| 105 | } |
| 106 | |
| 107 | fn add(&mut self, p: G, s: G::ScalarField) { |
| 108 | if let Some(x) = p.x() { |
| 109 | self.args |
| 110 | .entry(*x) |
| 111 | .and_modify(|(old_scalar, point)| { |
| 112 | // If the point or its negative already exists, update the scalar accordingly |
| 113 | if *point == p { |
| 114 | *old_scalar += s; |
| 115 | } else { |
| 116 | *old_scalar -= s; |
| 117 | debug_assert_eq!(point.into_group(), -p.into_group()); |
| 118 | } |
| 119 | }) |
| 120 | .or_insert((s, p)); |
| 121 | } else { |
| 122 | // If p is a point at infinity, then it doesn't impact the result |
| 123 | debug_assert!(p.is_zero()); |
| 124 | } |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | #[cfg(test)] |