diff --git a/Cargo.toml b/Cargo.toml index 2d375f3..b00ab1d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,10 @@ name = "othello" version = "0.1.0" edition = "2021" +[profile.release] +# for profiling +debug = true + [dependencies] num = "0.4" rand = "0.9" diff --git a/src/complexagent.rs b/src/complexagent.rs index 80895fb..da17e60 100644 --- a/src/complexagent.rs +++ b/src/complexagent.rs @@ -223,15 +223,18 @@ impl FutureMoves { stack.extend(self.arena[idx].children.iter().copied()); } - let mut new_arena = Vec::new(); + let mut new_arena = Vec::with_capacity(retain.iter().filter(|x| **x).count()); let mut index_map = vec![None; self.arena.len()]; - for (old_idx, _) in retain.iter().enumerate().rev().filter(|(_, a)| **a) { - index_map[old_idx] = Some(new_arena.len()); + for (old_idx, keep) in retain.iter().enumerate().rev() { let mut node = self.arena.remove(old_idx); - node.parent = node.parent.and_then(|p| index_map[p]); - node.children = node.children.iter().filter_map(|&c| index_map[c]).collect(); - new_arena.push(node); + if *keep { + index_map[old_idx] = Some(new_arena.len()); + + node.parent = node.parent.and_then(|p| index_map[p]); + node.children = node.children.iter().filter_map(|&c| index_map[c]).collect(); + new_arena.push(node); + } } self.arena = new_arena;