diff --git a/src/iterators/column_iterator.rs b/src/iterators/column_iterator.rs new file mode 100644 index 0000000..119d8fe --- /dev/null +++ b/src/iterators/column_iterator.rs @@ -0,0 +1,25 @@ +pub struct ColumnIterator<'a, T> { + map: &'a [Vec], + column: usize, + + i: usize, +} + +impl<'a, T> ColumnIterator<'a, T> { + pub fn new(map: &'a [Vec], 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 { + if self.i >= self.map.len() { + return None; + } + + self.i += 1; + Some(&self.map[self.i - 1][self.column]) + } +} diff --git a/src/iterators/mod.rs b/src/iterators/mod.rs new file mode 100644 index 0000000..c28d744 --- /dev/null +++ b/src/iterators/mod.rs @@ -0,0 +1,2 @@ +mod column_iterator; +pub use column_iterator::*; diff --git a/src/lib.rs b/src/lib.rs index 0286b60..d962d55 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,5 +10,8 @@ pub use testing::*; mod vectors; pub use vectors::*; +mod iterators; +pub use iterators::*; + mod data_structures; pub use data_structures::*;