treemap: use each_mut instead of mutate
This commit is contained in:
parent
88278f9c35
commit
2b6614f2e6
@ -636,14 +636,13 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
|
|||||||
fn heir_swap<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>,
|
fn heir_swap<K: TotalOrd, V>(node: &mut ~TreeNode<K, V>,
|
||||||
child: &mut Option<~TreeNode<K, V>>) {
|
child: &mut Option<~TreeNode<K, V>>) {
|
||||||
// *could* be done without recursion, but it won't borrow check
|
// *could* be done without recursion, but it won't borrow check
|
||||||
do child.mutate |mut child| {
|
for child.each_mut |x| {
|
||||||
if child.right.is_some() {
|
if x.right.is_some() {
|
||||||
heir_swap(node, &mut child.right);
|
heir_swap(node, &mut x.right);
|
||||||
} else {
|
} else {
|
||||||
node.key <-> child.key;
|
node.key <-> x.key;
|
||||||
node.value <-> child.value;
|
node.value <-> x.value;
|
||||||
}
|
}
|
||||||
child
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -689,7 +688,7 @@ fn remove<K: TotalOrd, V>(node: &mut Option<~TreeNode<K, V>>,
|
|||||||
save.level -= 1;
|
save.level -= 1;
|
||||||
|
|
||||||
if right_level > save.level {
|
if right_level > save.level {
|
||||||
do save.right.mutate |mut x| { x.level = save.level; x }
|
for save.right.each_mut |x| { x.level = save.level }
|
||||||
}
|
}
|
||||||
|
|
||||||
skew(save);
|
skew(save);
|
||||||
|
Loading…
Reference in New Issue
Block a user