[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:
parent
30cfcd9a88
commit
2a9e7cf74f
@ -19,6 +19,7 @@ pub struct Gatherer {
|
||||
heads: BTreeSet<u64>,
|
||||
tails: BTreeSet<u64>,
|
||||
entries: BTreeMap<u64, Entry>,
|
||||
back: BTreeMap<u64, u64>,
|
||||
}
|
||||
|
||||
impl Gatherer {
|
||||
@ -28,6 +29,7 @@ impl Gatherer {
|
||||
heads: BTreeSet::new(),
|
||||
tails: BTreeSet::new(),
|
||||
entries: BTreeMap::new(),
|
||||
back: BTreeMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
@ -59,6 +61,14 @@ impl Gatherer {
|
||||
if let Some(prev) = self.prev {
|
||||
let e = self.entries.get_mut(&prev).unwrap();
|
||||
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 {
|
||||
self.mark_head(b);
|
||||
}
|
||||
@ -153,6 +163,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn gather() {
|
||||
// the first value defines the input runs,
|
||||
// and the second defines expected sub sequences
|
||||
struct Test(Vec<Vec<u64>>, Vec<Vec<u64>>);
|
||||
|
||||
let tests = vec![
|
||||
@ -177,6 +189,10 @@ mod tests {
|
||||
],
|
||||
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 {
|
||||
|
Loading…
Reference in New Issue
Block a user