From 043ace987ce85649f616d9cc45d9be25f437f388 Mon Sep 17 00:00:00 2001 From: Jay Kickliter Date: Thu, 26 Oct 2023 16:38:42 -0600 Subject: [PATCH] Iterators take cell-stacks --- src/hex_tree_map.rs | 5 +++-- src/iteration.rs | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/hex_tree_map.rs b/src/hex_tree_map.rs index 6a19877..a73cd80 100644 --- a/src/hex_tree_map.rs +++ b/src/hex_tree_map.rs @@ -2,6 +2,7 @@ pub use crate::entry::{Entry, OccupiedEntry, VacantEntry}; use crate::{ + cell::CellStack, compaction::{Compactor, NullCompactor}, digits::Digits, node::Node, @@ -231,13 +232,13 @@ impl HexTreeMap { /// An iterator visiting all cell-value pairs in arbitrary order. pub fn iter(&self) -> impl Iterator { - 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 { - crate::iteration::IterMut::new(&mut self.nodes) + crate::iteration::IterMut::new(&mut self.nodes, CellStack::new()) } } diff --git a/src/iteration.rs b/src/iteration.rs index b08f2ae..cf027fd 100644 --- a/src/iteration.rs +++ b/src/iteration.rs @@ -29,12 +29,11 @@ pub(crate) struct Iter<'a, V> { } impl<'a, V> Iter<'a, V> { - pub(crate) fn new(base: &'a [Option>>]) -> Self { + pub(crate) fn new(base: &'a [Option>>], 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) } @@ -119,12 +118,11 @@ pub(crate) struct IterMut<'a, V> { } impl<'a, V> IterMut<'a, V> { - pub(crate) fn new(base: &'a mut [Option>>]) -> Self { + pub(crate) fn new(base: &'a mut [Option>>], 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) }