[thin_dump (rust)] Split runs at the position with multiple references

That is, an element with multiple references will serve as the beginning
of an atomic run.
This commit is contained in:
Ming-Hung Tsai 2021-05-10 20:57:11 +08:00
parent 30cfcd9a88
commit 2a9e7cf74f

View File

@ -19,6 +19,7 @@ pub struct Gatherer {
heads: BTreeSet<u64>, heads: BTreeSet<u64>,
tails: BTreeSet<u64>, tails: BTreeSet<u64>,
entries: BTreeMap<u64, Entry>, entries: BTreeMap<u64, Entry>,
back: BTreeMap<u64, u64>,
} }
impl Gatherer { impl Gatherer {
@ -28,6 +29,7 @@ impl Gatherer {
heads: BTreeSet::new(), heads: BTreeSet::new(),
tails: BTreeSet::new(), tails: BTreeSet::new(),
entries: BTreeMap::new(), entries: BTreeMap::new(),
back: BTreeMap::new(),
} }
} }
@ -59,6 +61,14 @@ impl Gatherer {
if let Some(prev) = self.prev { if let Some(prev) = self.prev {
let e = self.entries.get_mut(&prev).unwrap(); let e = self.entries.get_mut(&prev).unwrap();
e.neighbours.insert(b); e.neighbours.insert(b);
if let Some(back) = self.back.get(&b) {
if *back != prev {
self.mark_head(b);
}
} else {
self.back.insert(b, prev);
}
} else { } else {
self.mark_head(b); self.mark_head(b);
} }
@ -153,6 +163,8 @@ mod tests {
#[test] #[test]
fn gather() { fn gather() {
// the first value defines the input runs,
// and the second defines expected sub sequences
struct Test(Vec<Vec<u64>>, Vec<Vec<u64>>); struct Test(Vec<Vec<u64>>, Vec<Vec<u64>>);
let tests = vec![ let tests = vec![
@ -177,6 +189,10 @@ mod tests {
], ],
vec![vec![1], vec![2], vec![3, 4], vec![5, 6]], vec![vec![1], vec![2], vec![3, 4], vec![5, 6]],
), ),
Test(
vec![vec![2, 3, 4, 5], vec![2, 3, 4, 6], vec![1, 3, 4, 5]],
vec![vec![1], vec![2], vec![3, 4], vec![5], vec![6]],
),
]; ];
for t in tests { for t in tests {