correct acyclic iteration.
@@ -146,14 +146,8 @@ pub struct HeapCellAcyclicIterator<HeapCellIter> {
impl<HeapCellIter: MutStackHeapCellIterator> HeapCellAcyclicIterator<HeapCellIter>
{
- pub fn new(mut iter: HeapCellIter) -> Self {
- let mut seen = HashSet::new();
-
- if let Some(addr) = iter.stack().last() {
- seen.insert(addr.clone());
- }
-
- HeapCellAcyclicIterator { iter, seen }
+ pub fn new(iter: HeapCellIter) -> Self {
+ HeapCellAcyclicIterator { iter, seen: HashSet::new() }
}
}
@@ -164,19 +158,16 @@ impl<HeapCellIter> Iterator for HeapCellAcyclicIterator<HeapCellIter>
type Item = HeapCellValue;
fn next(&mut self) -> Option<Self::Item> {
- while let Some(hcv) = self.iter.next() {
- if let Some(addr) = self.iter.stack().pop() {
+ while let Some(addr) = self.iter.stack().pop() {
if self.seen.contains(&addr) {
continue;
} else {
self.iter.stack().push(addr.clone());
self.seen.insert(addr);
+ break;
}
}
- return Some(hcv);
- }
-
- None
+ self.iter.next()
}
}
