Skip to content

Commit

Permalink
Revert "Merge pull request #4633 from thestinger/treemap"
Browse files Browse the repository at this point in the history
I was too hasty in merging -- this needs a snapshot.

This reverts commit 4a7e1ab, reversing
changes made to e447521.
  • Loading branch information
catamorphism committed Jan 25, 2013
1 parent 18f1dba commit d73077f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
12 changes: 8 additions & 4 deletions src/libstd/priority_queue.rs
Expand Up @@ -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);
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -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]);

Expand Down
17 changes: 11 additions & 6 deletions src/libstd/treemap.rs
Expand Up @@ -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);
Expand All @@ -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);
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit d73077f

Please sign in to comment.