refocus_tree: use hashmap for index_map
This commit is contained in:
parent
f4007c2d42
commit
82b679095c
@ -528,7 +528,11 @@ impl FutureMoves {
|
|||||||
stack.extend(self.arena[idx].children.iter());
|
stack.extend(self.arena[idx].children.iter());
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut index_map = vec![None; self.arena.len()];
|
let mut index_map: HashMap<
|
||||||
|
usize,
|
||||||
|
usize,
|
||||||
|
BuildHasherDefault<nohash_hasher::NoHashHasher<usize>>,
|
||||||
|
> = HashMap::with_capacity_and_hasher(self.arena.len(), BuildHasherDefault::default());
|
||||||
|
|
||||||
let (indexes, moves): (Vec<(usize, usize)>, Vec<Move>) = retain
|
let (indexes, moves): (Vec<(usize, usize)>, Vec<Move>) = retain
|
||||||
.into_iter()
|
.into_iter()
|
||||||
@ -541,7 +545,7 @@ impl FutureMoves {
|
|||||||
.unzip();
|
.unzip();
|
||||||
|
|
||||||
for (new_idx, old_idx) in indexes {
|
for (new_idx, old_idx) in indexes {
|
||||||
index_map[old_idx] = Some(new_idx);
|
index_map.insert(old_idx, new_idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
self.arena = moves
|
self.arena = moves
|
||||||
@ -549,13 +553,12 @@ impl FutureMoves {
|
|||||||
.map(|mut node| {
|
.map(|mut node| {
|
||||||
node.parent = node
|
node.parent = node
|
||||||
.parent
|
.parent
|
||||||
.and_then(|parent| index_map.get(parent))
|
.and_then(|parent| index_map.get(&parent).copied());
|
||||||
.and_then(|&x| x);
|
|
||||||
|
|
||||||
for c in node.children.as_mut_slice() {
|
for c in node.children.as_mut_slice() {
|
||||||
*c = index_map
|
*c = index_map
|
||||||
.get(*c)
|
.get(c)
|
||||||
.and_then(|&x| x)
|
.copied()
|
||||||
.expect("index_map should contain the child's index");
|
.expect("index_map should contain the child's index");
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -563,7 +566,7 @@ impl FutureMoves {
|
|||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
self.current_root = index_map[root];
|
self.current_root = index_map.get(&root).copied();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user