Skip to content

Commit

Permalink
Move contructors to the top of PriorityQueue.
Browse files Browse the repository at this point in the history
  • Loading branch information
treeman committed Jul 24, 2014
1 parent 9e2bb9d commit 87ef2f3
Showing 1 changed file with 19 additions and 19 deletions.
38 changes: 19 additions & 19 deletions src/libcollections/priority_queue.rs
Expand Up @@ -180,6 +180,25 @@ impl<T: Ord> Default for PriorityQueue<T> {
}

impl<T: Ord> PriorityQueue<T> {
/// Create an empty PriorityQueue
pub fn new() -> PriorityQueue<T> { PriorityQueue{data: vec!(),} }

/// Create an empty PriorityQueue with capacity `capacity`
pub fn with_capacity(capacity: uint) -> PriorityQueue<T> {
PriorityQueue { data: Vec::with_capacity(capacity) }
}

/// Create a PriorityQueue from a vector (heapify)
pub fn from_vec(xs: Vec<T>) -> PriorityQueue<T> {
let mut q = PriorityQueue{data: xs,};
let mut n = q.len() / 2;
while n > 0 {
n -= 1;
q.siftdown(n)
}
q
}

/// An iterator visiting all values in underlying vector, in
/// arbitrary order.
pub fn iter<'a>(&'a self) -> Items<'a, T> {
Expand Down Expand Up @@ -278,25 +297,6 @@ impl<T: Ord> PriorityQueue<T> {
q.into_vec()
}

/// Create an empty PriorityQueue
pub fn new() -> PriorityQueue<T> { PriorityQueue{data: vec!(),} }

/// Create an empty PriorityQueue with capacity `capacity`
pub fn with_capacity(capacity: uint) -> PriorityQueue<T> {
PriorityQueue { data: Vec::with_capacity(capacity) }
}

/// Create a PriorityQueue from a vector (heapify)
pub fn from_vec(xs: Vec<T>) -> PriorityQueue<T> {
let mut q = PriorityQueue{data: xs,};
let mut n = q.len() / 2;
while n > 0 {
n -= 1;
q.siftdown(n)
}
q
}

// The implementations of siftup and siftdown use unsafe blocks in
// order to move an element out of the vector (leaving behind a
// zeroed element), shift along the others and move it back into the
Expand Down

0 comments on commit 87ef2f3

Please sign in to comment.