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
.into_iter()
.map(|mut node| {
if let Some(parent) = node.parent.as_mut() {
if let Some(new_parent) = index_map[*parent] {
*parent = new_parent;
} else {
// make sure we don't have dangling parents
node.parent = None;
}
}
node.parent = node
.parent
.and_then(|parent| index_map.get(parent).and_then(|&x| x));
for c in node.children.as_mut_slice() {
debug_assert_ne!(
index_map.get(*c).and_then(|&x| x),
None,
"index_map should contain the child's index"
);
*c = unsafe { index_map.get_unchecked(*c).unwrap_unchecked() };
*c = index_map
.get(*c)
.and_then(|&x| x)
.expect("index_map should contain the child's index");
}
node