fix refocus_tree

This commit is contained in:
Simon Gardling 2025-02-20 22:01:12 -05:00
parent 8de01ffd57
commit cb129a96cf
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -308,15 +308,21 @@ impl FutureMoves {
let mut index_map = vec![None; self.arena.len()];
self.arena = retain
let new_start: Vec<(usize, (usize, Move))> = retain
.into_iter()
.enumerate() // old_idx
.zip(self.arena.drain(..))
.flat_map(|((old_idx, keep), node)| keep.then_some((old_idx, node))) // filter out unrelated nodes
.enumerate() // new_idx
.map(|(new_idx, (old_idx, mut node))| {
index_map[old_idx] = Some(new_idx);
.collect();
for &(new_idx, (old_idx, _)) in &new_start {
index_map[old_idx] = Some(new_idx);
}
self.arena = new_start
.into_iter()
.map(|(_, (_, mut node))| {
if let Some(parent) = node.parent.as_mut() {
if let Some(new_parent) = index_map[*parent] {
*parent = new_parent;
@ -331,7 +337,7 @@ impl FutureMoves {
*c = new_c;
true
} else {
false
panic!("node is not kept in move");
}
});