Skip to content

Commit 285496b

Browse files
thestingerbrson
authored andcommitted
priority_queue: make from_vec a static method
1 parent 757a2af commit 285496b

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

src/libstd/priority_queue.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,16 @@ impl <T: Copy Ord> PriorityQueue<T> {
9191
q.to_vec()
9292
}
9393

94+
static pub pure fn from_vec(xs: ~[T]) -> PriorityQueue<T> {
95+
let mut q = PriorityQueue{data: xs,};
96+
let mut n = q.len() / 2;
97+
while n > 0 {
98+
n -= 1;
99+
unsafe { q.siftup(n) }; // purity-checking workaround
100+
}
101+
q
102+
}
103+
94104
priv fn siftdown(&mut self, startpos: uint, pos: uint) {
95105
let mut pos = pos;
96106
let newitem = self.data[pos];
@@ -133,20 +143,11 @@ impl <T: Copy Ord> PriorityQueue<T> {
133143
}
134144
}
135145

136-
pub pure fn from_vec<T: Copy Ord>(xs: ~[T]) -> PriorityQueue<T> {
137-
let mut q = PriorityQueue{data: xs,};
138-
let mut n = q.len() / 2;
139-
while n > 0 {
140-
n -= 1;
141-
unsafe { q.siftup(n) }; // purity-checking workaround
142-
}
143-
q
144-
}
145-
146146
#[cfg(test)]
147147
mod tests {
148148
use sort::merge_sort;
149149
use core::cmp::le;
150+
use PriorityQueue::from_vec;
150151

151152
#[test]
152153
fn test_top_and_pop() {

0 commit comments

Comments
 (0)