Revert "Merge pull request #4633 from thestinger/treemap"

I was too hasty in merging -- this needs a snapshot.

This reverts commit 4a7e1ab374, reversing
changes made to e447521c1c.
This commit is contained in:
Tim Chevalier 2013-01-25 13:39:04 -08:00
parent 18f1dba510
commit d73077f82d
2 changed files with 19 additions and 10 deletions

View File

@ -76,7 +76,8 @@ impl <T: Ord> PriorityQueue<T> {
}
/// Optimized version of a push followed by a pop
fn push_pop(&mut self, mut item: T) -> T {
fn push_pop(&mut self, item: T) -> T {
let mut item = item;
if !self.is_empty() && self.data[0] > item {
item <-> self.data[0];
self.siftdown(0);
@ -85,7 +86,8 @@ impl <T: Ord> PriorityQueue<T> {
}
/// Optimized version of a pop followed by a push - fails if empty
fn replace(&mut self, mut item: T) -> T {
fn replace(&mut self, item: T) -> T {
let mut item = item;
item <-> self.data[0];
self.siftdown(0);
item
@ -127,8 +129,9 @@ impl <T: Ord> PriorityQueue<T> {
// vector over the junk element. This reduces the constant factor
// compared to using swaps, which involves twice as many moves.
priv fn siftup(&mut self, start: uint, mut pos: uint) {
priv fn siftup(&mut self, start: uint, pos: uint) {
unsafe {
let mut pos = pos;
let new = move *addr_of(&self.data[pos]);
while pos > start {
@ -146,8 +149,9 @@ impl <T: Ord> PriorityQueue<T> {
}
}
priv fn siftdown_range(&mut self, mut pos: uint, end: uint) {
priv fn siftdown_range(&mut self, pos: uint, end: uint) {
unsafe {
let mut pos = pos;
let start = pos;
let new = move *addr_of(&self.data[pos]);

View File

@ -526,8 +526,9 @@ pure fn each_reverse<K: Ord, V>(node: &Option<~TreeNode<K, V>>,
}
// Remove left horizontal link by rotating right
fn skew<K: Ord, V>(mut node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
fn skew<K: Ord, V>(node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
if node.left.map_default(false, |x| x.level == node.level) {
let mut node = node;
let mut save = node.left.swap_unwrap();
node.left <-> save.right; // save.right now None
save.right = Some(node);
@ -539,9 +540,10 @@ fn skew<K: Ord, V>(mut node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
// Remove dual horizontal link by rotating left and increasing level of
// the parent
fn split<K: Ord, V>(mut node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
fn split<K: Ord, V>(node: ~TreeNode<K, V>) -> ~TreeNode<K, V> {
if node.right.map_default(false,
|x| x.right.map_default(false, |y| y.level == node.level)) {
let mut node = node;
let mut save = node.right.swap_unwrap();
node.right <-> save.left; // save.left now None
save.left = Some(node);
@ -580,7 +582,8 @@ fn remove<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: &K) -> bool {
fn heir_swap<K: Ord, V>(node: &mut TreeNode<K, V>,
child: &mut Option<~TreeNode<K, V>>) {
// *could* be done without recursion, but it won't borrow check
do child.mutate |mut child| {
do child.mutate |child| {
let mut child = child;
if child.right.is_some() {
heir_swap(&mut *node, &mut child.right);
} else {
@ -633,13 +636,15 @@ fn remove<K: Ord, V>(node: &mut Option<~TreeNode<K, V>>, key: &K) -> bool {
save.level -= 1;
if right_level > save.level {
do save.right.mutate |mut x| { x.level = save.level; x }
do save.right.mutate |x| {
let mut x = x; x.level = save.level; x
}
}
save = skew(save);
do save.right.mutate |mut right| {
right = skew(right);
do save.right.mutate |right| {
let mut right = skew(right);
right.right.mutate(skew);
right
}