set up heap_var Cow in heap_print.rs

This commit is contained in:
Mark Thom
2018-05-04 20:15:39 -06:00
parent 2df82e6b01
commit afc5736418
2 changed files with 52 additions and 5 deletions

View File

@@ -120,7 +120,7 @@ impl MachineState {
pub fn pre_order_iter<'a>(&'a self, a: Addr) -> HCPreOrderIterator<'a> {
HCPreOrderIterator::new(self, a)
}
pub fn post_order_iter<'a>(&'a self, a: Addr) -> HCPostOrderIterator<'a> {
HCPostOrderIterator::new(HCPreOrderIterator::new(self, a))
}
@@ -179,6 +179,37 @@ where HCIter: Iterator<Item=HeapCellValue> + MutStackHCIterator
}
}
pub struct HCDerefAcyclicIterator<HCIter> {
iter: HCIter,
seen: HashSet<Addr>
}
impl<HCIter: MutStackHCIterator> HCDerefAcyclicIterator<HCIter>
{
pub fn new(iter: HCIter) -> Self {
HCDerefAcyclicIterator { iter, seen: HashSet::new() }
}
}
impl<HCIter> Iterator for HCDerefAcyclicIterator<HCIter>
where HCIter: Iterator<Item=HeapCellValue> + MutStackHCIterator
{
type Item = HeapCellValue;
fn next(&mut self) -> Option<Self::Item> {
loop {
match self.iter.next() {
Some(HeapCellValue::Addr(addr)) =>
if !self.seen.contains(&addr) {
self.seen.insert(addr.clone());
return Some(HeapCellValue::Addr(addr));
},
item => return item
}
}
}
}
pub struct HCZippedAcyclicIterator<HCIter> {
i1: HCIter,
i2: HCIter,