blob: 059d7e30950fc21a6828425b9749aac44a02f055 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
use crate::number::Number;
use std::cmp;
use std::iter::{Take, Zip};
pub struct Iter {
index: usize,
data: Vec<Number>,
degree: usize,
}
impl Iter {
pub fn new(data: Vec<Number>, degree: usize) -> Iter {
Iter {
index: 0,
data,
degree,
}
}
pub fn zip(self, other: Self) -> Zip<Take<Iter>, Take<Iter>> {
let deg = cmp::max(self.degree, other.degree) + 1;
let a = self.take(deg);
let b = other.take(deg);
a.zip(b)
}
}
impl Iterator for Iter {
type Item = Number;
fn next(&mut self) -> Option<Number> {
self.index += 1;
if self.index <= self.data.len() {
Some(self.data[self.index - 1])
} else {
Some(0.0)
}
}
}
|