iterator improvements

This commit is contained in:
Simon Gardling 2025-02-10 17:08:57 -05:00
parent 2825186fbb
commit 3e2ab2fd32
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -140,8 +140,7 @@ impl FutureMoves {
.arena
.iter()
.enumerate()
.filter(|(_, node)| self.depth_of(node.parent) == depth)
.map(|(idx, _)| idx)
.filter_map(|(idx, node)| (self.depth_of(node.parent) == depth).then_some(idx))
.collect();
for idx in nodes_at_depth {
@ -180,24 +179,21 @@ impl FutureMoves {
.arena
.iter()
.enumerate()
.filter(|(_, node)| node.parent.is_none())
.map(|(idx, _)| idx)
.filter_map(|(idx, node)| node.parent.is_none().then_some(idx))
.collect(),
};
root_nodes
.into_iter()
.max_by_key(|&idx| self.arena[idx].value)
.map(|idx| (self.arena[idx].i, self.arena[idx].j))
.map(|idx| &self.arena[idx])
.max_by_key(|x| x.value)
.map(|x| (x.i, x.j))
}
pub fn update_root(&mut self, i: usize, j: usize) -> bool {
let new_root = self
.arena
.iter()
.enumerate()
.find(|(_, node)| node.parent == self.current_root && node.i == i && node.j == j)
.map(|(idx, _)| idx);
let new_root = self.arena.iter().enumerate().find_map(|(idx, node)| {
(node.parent == self.current_root && node.i == i && node.j == j).then_some(idx)
});
if let Some(root) = new_root {
self.current_root = Some(root);