diff options
| author | Jonas Hietala <tradet.h@gmail.com> | 2014-07-21 11:35:49 +0200 |
|---|---|---|
| committer | Jonas Hietala <tradet.h@gmail.com> | 2014-07-24 11:40:22 +0200 |
| commit | 87ef2f390b7e463ce3e64973abce02be8c7a9ceb (patch) | |
| tree | d81f7a7c04ad9a87abf0274d3f46fdea067bae15 | |
| parent | 9e2bb9d67bb47b9a3a6c7389efa45cefc33206a6 (diff) | |
| download | rust-87ef2f390b7e463ce3e64973abce02be8c7a9ceb.tar.gz rust-87ef2f390b7e463ce3e64973abce02be8c7a9ceb.zip | |
Move contructors to the top of PriorityQueue.
| -rw-r--r-- | src/libcollections/priority_queue.rs | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/src/libcollections/priority_queue.rs b/src/libcollections/priority_queue.rs index 6e1a3ec1cb6..6732f37f8b5 100644 --- a/src/libcollections/priority_queue.rs +++ b/src/libcollections/priority_queue.rs @@ -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> { @@ -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 |
