Skip to content

Commit 6b0c52e

Browse files
thestingerbrson
authored andcommitted
---
yaml --- r: 34151 b: refs/heads/snap-stage3 c: 757a2af h: refs/heads/master i: 34149: acf7c01 34147: efd1115 34143: e22c2dc v: v3
1 parent 5da3297 commit 6b0c52e

File tree

2 files changed

+18
-21
lines changed

2 files changed

+18
-21
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: cd6f24f9d14ac90d167386a56e7a6ac1f0318195
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: dd2b32be56945824e1e900d9748274633d6db6c1
4+
refs/heads/snap-stage3: 757a2afb6b80cb4dbdcb8069f1af511ec42e8670
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/priority_queue.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,21 @@ impl <T: Copy Ord> PriorityQueue<T> {
7676
ret
7777
}
7878

79+
/// Consume the PriorityQueue and return the underlying vector
80+
pure fn to_vec(self) -> ~[T] { let PriorityQueue{data: v} = self; v }
81+
82+
/// Consume the PriorityQueue and return a vector in sorted (ascending) order
83+
pure fn to_sorted_vec(self) -> ~[T] {
84+
let mut q = self;
85+
let mut end = q.len() - 1;
86+
while end > 0 {
87+
q.data[end] <-> q.data[0];
88+
end -= 1;
89+
unsafe { q.siftup_range(0, end) } // purity-checking workaround
90+
}
91+
q.to_vec()
92+
}
93+
7994
priv fn siftdown(&mut self, startpos: uint, pos: uint) {
8095
let mut pos = pos;
8196
let newitem = self.data[pos];
@@ -118,24 +133,6 @@ impl <T: Copy Ord> PriorityQueue<T> {
118133
}
119134
}
120135

121-
/// Consume the PriorityQueue and return the underlying vector
122-
pub pure fn to_vec<T: Copy Ord>(q: PriorityQueue<T>) -> ~[T] {
123-
let PriorityQueue{data: v} = q;
124-
v
125-
}
126-
127-
/// Consume the PriorityQueue and return a vector in sorted (ascending) order
128-
pub pure fn to_sorted_vec<T: Copy Ord>(q: PriorityQueue<T>) -> ~[T] {
129-
let mut q = q;
130-
let mut end = q.len() - 1;
131-
while end > 0 {
132-
q.data[end] <-> q.data[0];
133-
end -= 1;
134-
unsafe { q.siftup_range(0, end) } // purity-checking workaround
135-
}
136-
to_vec(q)
137-
}
138-
139136
pub pure fn from_vec<T: Copy Ord>(xs: ~[T]) -> PriorityQueue<T> {
140137
let mut q = PriorityQueue{data: xs,};
141138
let mut n = q.len() / 2;
@@ -215,7 +212,7 @@ mod tests {
215212
#[test]
216213
fn test_to_sorted_vec() {
217214
let data = ~[2, 4, 6, 2, 1, 8, 10, 3, 5, 7, 0, 9, 1];
218-
assert to_sorted_vec(from_vec(data)) == merge_sort(data, le);
215+
assert from_vec(data).to_sorted_vec() == merge_sort(data, le);
219216
}
220217

221218
#[test]
@@ -248,6 +245,6 @@ mod tests {
248245
fn test_to_vec() {
249246
let data = ~[1, 3, 5, 7, 9, 2, 4, 6, 8, 0];
250247
let heap = from_vec(copy data);
251-
assert merge_sort(to_vec(heap), le) == merge_sort(data, le);
248+
assert merge_sort(heap.to_vec(), le) == merge_sort(data, le);
252249
}
253250
}

0 commit comments

Comments
 (0)