Skip to content

Commit 46fcb94

Browse files
committed
clean up doc
1 parent 446bbfe commit 46fcb94

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

poly/src/polynomial/univariate/dense.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -321,38 +321,32 @@ impl<'a, F: Field> Add<&'a SparsePolynomial<F>> for &DensePolynomial<F> {
321321

322322
#[inline]
323323
fn add(self, other: &'a SparsePolynomial<F>) -> DensePolynomial<F> {
324-
// If `self` is zero, the result is `other` (as adding zero doesn't change anything).
325324
if self.is_zero() {
326325
return other.clone().into();
327326
}
328327

329-
// If `other` is zero, the result is `self` (as adding zero doesn't change anything).
330328
if other.is_zero() {
331329
return self.clone();
332330
}
333331

334332
let mut result = self.clone();
335333

336-
// Prepare a vector to store the coefficients of the upper terms of the addition.
334+
// If `other` has higher degree than `self`, create a dense vector
335+
// storing the upper coefficients of the addition
337336
let mut upper_coeffs = vec![F::zero(); other.degree().saturating_sub(result.degree())];
338337

339-
// Iterate over the sparse polynomial's non-zero terms.
340338
for (pow, coeff) in other.iter() {
341-
// If the power `pow` is within the degree of `result`, add the coefficient to the corresponding term.
342339
if let Some(target) = result.coeffs.get_mut(*pow) {
343340
*target += coeff;
344341
} else {
345-
// Otherwise, store the coefficient in the `upper_coeffs` vector at the appropriate position.
346-
//
347-
// The index is adjusted by subtracting the current length of `result.coeffs`.
348342
upper_coeffs[pow - result.coeffs.len()] = *coeff;
349343
}
350344
}
351345

352346
// Extend the coefficient vector of `result` with the upper terms.
353347
result.coeffs.extend(upper_coeffs);
354348

355-
// Remove any trailing zeros from the coefficient vector to ensure it represents the correct polynomial.
349+
// Remove any leading zeros.
356350
// For example: `0 * x^2 + 0 * x + 1` should be represented as `1`.
357351
result.truncate_leading_zeros();
358352

0 commit comments

Comments
 (0)