From 1891436bf1d6b18f1dded15ae693f90f8a6ab975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juan=20Manuel=20Tom=C3=A1s?= Date: Mon, 11 Jan 2021 19:44:07 -0300 Subject: Move zip implementation from poly to poly/iter Zip seems more appropriate on an iterator. --- src/poly.rs | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'src/poly.rs') diff --git a/src/poly.rs b/src/poly.rs index 9c95796..0e1cd9e 100644 --- a/src/poly.rs +++ b/src/poly.rs @@ -2,10 +2,8 @@ mod iter; use crate::number::Number; use iter::Iter; -use std::cmp; use std::cmp::Ordering; use std::ops::{Add, Sub, Mul, Rem}; -use std::iter::{Zip, Take}; #[derive(PartialEq, Debug)] pub struct Poly(pub Vec); @@ -20,14 +18,7 @@ impl Poly { } fn iter(&self) -> Iter { - Iter::new(self.0.clone()) - } - - fn zip(&self, other: &Self) -> Zip, Take> { - let deg = cmp::max(self.degree(), other.degree()) + 1; - let a = self.iter().take(deg); - let b = other.iter().take(deg); - a.zip(b) + Iter::new(self.0.clone(), self.degree()) } pub fn eval(&self, n: Number) -> Number { @@ -52,7 +43,7 @@ impl Add for &Poly { type Output = Poly; fn add(self, other: Self) -> Poly { - Poly(self.zip(other).map(|(x, y)| {x + y}).collect()) + Poly(self.iter().zip(other.iter()).map(|(x, y)| {x + y}).collect()) } } @@ -60,7 +51,7 @@ impl Sub for &Poly { type Output = Poly; fn sub(self, other: Self) -> Poly { - Poly(self.zip(other).map(|(x, y)| {x - y}).collect()) + Poly(self.iter().zip(other.iter()).map(|(x, y)| {x - y}).collect()) } } -- cgit v1.2.3