1
Fork 0

use mut function argument syntax in priority_queue

This commit is contained in:
Daniel Micay 2013-01-25 13:28:43 -05:00
parent aff3db26aa
commit ca8f09a39e

View file

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