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