iterator improvements
This commit is contained in:
parent
2825186fbb
commit
3e2ab2fd32
@ -140,8 +140,7 @@ impl FutureMoves {
|
|||||||
.arena
|
.arena
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|(_, node)| self.depth_of(node.parent) == depth)
|
.filter_map(|(idx, node)| (self.depth_of(node.parent) == depth).then_some(idx))
|
||||||
.map(|(idx, _)| idx)
|
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
for idx in nodes_at_depth {
|
for idx in nodes_at_depth {
|
||||||
@ -180,24 +179,21 @@ impl FutureMoves {
|
|||||||
.arena
|
.arena
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.filter(|(_, node)| node.parent.is_none())
|
.filter_map(|(idx, node)| node.parent.is_none().then_some(idx))
|
||||||
.map(|(idx, _)| idx)
|
|
||||||
.collect(),
|
.collect(),
|
||||||
};
|
};
|
||||||
|
|
||||||
root_nodes
|
root_nodes
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.max_by_key(|&idx| self.arena[idx].value)
|
.map(|idx| &self.arena[idx])
|
||||||
.map(|idx| (self.arena[idx].i, self.arena[idx].j))
|
.max_by_key(|x| x.value)
|
||||||
|
.map(|x| (x.i, x.j))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn update_root(&mut self, i: usize, j: usize) -> bool {
|
pub fn update_root(&mut self, i: usize, j: usize) -> bool {
|
||||||
let new_root = self
|
let new_root = self.arena.iter().enumerate().find_map(|(idx, node)| {
|
||||||
.arena
|
(node.parent == self.current_root && node.i == i && node.j == j).then_some(idx)
|
||||||
.iter()
|
});
|
||||||
.enumerate()
|
|
||||||
.find(|(_, node)| node.parent == self.current_root && node.i == i && node.j == j)
|
|
||||||
.map(|(idx, _)| idx);
|
|
||||||
|
|
||||||
if let Some(root) = new_root {
|
if let Some(root) = new_root {
|
||||||
self.current_root = Some(root);
|
self.current_root = Some(root);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user