From 87ef2f390b7e463ce3e64973abce02be8c7a9ceb Mon Sep 17 00:00:00 2001 From: Jonas Hietala Date: Mon, 21 Jul 2014 11:35:49 +0200 Subject: [PATCH] Move contructors to the top of PriorityQueue. --- src/libcollections/priority_queue.rs | 38 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/src/libcollections/priority_queue.rs b/src/libcollections/priority_queue.rs index 6e1a3ec1cb6c..6732f37f8b50 100644 --- a/src/libcollections/priority_queue.rs +++ b/src/libcollections/priority_queue.rs @@ -180,6 +180,25 @@ impl Default for PriorityQueue { } impl PriorityQueue { + /// Create an empty PriorityQueue + pub fn new() -> PriorityQueue { PriorityQueue{data: vec!(),} } + + /// Create an empty PriorityQueue with capacity `capacity` + pub fn with_capacity(capacity: uint) -> PriorityQueue { + PriorityQueue { data: Vec::with_capacity(capacity) } + } + + /// Create a PriorityQueue from a vector (heapify) + pub fn from_vec(xs: Vec) -> PriorityQueue { + 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 PriorityQueue { q.into_vec() } - /// Create an empty PriorityQueue - pub fn new() -> PriorityQueue { PriorityQueue{data: vec!(),} } - - /// Create an empty PriorityQueue with capacity `capacity` - pub fn with_capacity(capacity: uint) -> PriorityQueue { - PriorityQueue { data: Vec::with_capacity(capacity) } - } - - /// Create a PriorityQueue from a vector (heapify) - pub fn from_vec(xs: Vec) -> PriorityQueue { - 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