Skip to content

Commit

Permalink
Iterators take cell-stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
JayKickliter committed Oct 26, 2023
1 parent 2c200f0 commit 043ace9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/hex_tree_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

pub use crate::entry::{Entry, OccupiedEntry, VacantEntry};
use crate::{
cell::CellStack,
compaction::{Compactor, NullCompactor},
digits::Digits,
node::Node,
Expand Down Expand Up @@ -231,13 +232,13 @@ impl<V, C> HexTreeMap<V, C> {

/// An iterator visiting all cell-value pairs in arbitrary order.
pub fn iter(&self) -> impl Iterator<Item = (Cell, &V)> {
crate::iteration::Iter::new(&self.nodes)
crate::iteration::Iter::new(&self.nodes, CellStack::new())
}

/// An iterator visiting all cell-value pairs in arbitrary order
/// with mutable references to the values.
pub fn iter_mut(&mut self) -> impl Iterator<Item = (Cell, &mut V)> {
crate::iteration::IterMut::new(&mut self.nodes)
crate::iteration::IterMut::new(&mut self.nodes, CellStack::new())
}
}

Expand Down
6 changes: 2 additions & 4 deletions src/iteration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ pub(crate) struct Iter<'a, V> {
}

impl<'a, V> Iter<'a, V> {
pub(crate) fn new(base: &'a [Option<Box<Node<V>>>]) -> Self {
pub(crate) fn new(base: &'a [Option<Box<Node<V>>>], mut cell_stack: CellStack) -> Self {
let mut iter = make_node_stack_iter(base);
let curr = iter.next();
let mut stack = Vec::with_capacity(16);
stack.push(iter);
let mut cell_stack = CellStack::new();
if let Some((digit, _)) = curr {
cell_stack.push(digit as u8)
}
Expand Down Expand Up @@ -119,12 +118,11 @@ pub(crate) struct IterMut<'a, V> {
}

impl<'a, V> IterMut<'a, V> {
pub(crate) fn new(base: &'a mut [Option<Box<Node<V>>>]) -> Self {
pub(crate) fn new(base: &'a mut [Option<Box<Node<V>>>], mut cell_stack: CellStack) -> Self {
let mut iter = make_node_stack_iter_mut(base);
let curr = iter.next();
let mut stack = Vec::with_capacity(16);
stack.push(iter);
let mut cell_stack = CellStack::new();
if let Some((digit, _)) = curr {
cell_stack.push(digit as u8)
}
Expand Down

0 comments on commit 043ace9

Please sign in to comment.