improve pruning tree indexing logic

This commit is contained in:
Simon Gardling 2025-02-28 21:14:37 -05:00
parent 97d914238c
commit 86d4455321
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -442,22 +442,15 @@ impl FutureMoves {
self.arena = moves self.arena = moves
.into_iter() .into_iter()
.map(|mut node| { .map(|mut node| {
if let Some(parent) = node.parent.as_mut() { node.parent = node
if let Some(new_parent) = index_map[*parent] { .parent
*parent = new_parent; .and_then(|parent| index_map.get(parent).and_then(|&x| x));
} else {
// make sure we don't have dangling parents
node.parent = None;
}
}
for c in node.children.as_mut_slice() { for c in node.children.as_mut_slice() {
debug_assert_ne!( *c = index_map
index_map.get(*c).and_then(|&x| x), .get(*c)
None, .and_then(|&x| x)
"index_map should contain the child's index" .expect("index_map should contain the child's index");
);
*c = unsafe { index_map.get_unchecked(*c).unwrap_unchecked() };
} }
node node