1
0
Fork 0

lib: implement column iterator

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2023-07-06 19:08:53 +02:00
parent c14c785355
commit 43c39a3ec0
Signed by: mfocko
GPG key ID: 7C47D46246790496
3 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,25 @@
pub struct ColumnIterator<'a, T> {
map: &'a [Vec<T>],
column: usize,
i: usize,
}
impl<'a, T> ColumnIterator<'a, T> {
pub fn new(map: &'a [Vec<T>], column: usize) -> ColumnIterator<'a, T> {
Self { map, column, i: 0 }
}
}
impl<'a, T> Iterator for ColumnIterator<'a, T> {
type Item = &'a T;
fn next(&mut self) -> Option<Self::Item> {
if self.i >= self.map.len() {
return None;
}
self.i += 1;
Some(&self.map[self.i - 1][self.column])
}
}

2
src/iterators/mod.rs Normal file
View file

@ -0,0 +1,2 @@
mod column_iterator;
pub use column_iterator::*;

View file

@ -10,5 +10,8 @@ pub use testing::*;
mod vectors;
pub use vectors::*;
mod iterators;
pub use iterators::*;
mod data_structures;
pub use data_structures::*;