Skip to content

Commit 749a70a

Browse files
thestingerbrson
authored andcommitted
---
yaml --- r: 36763 b: refs/heads/try2 c: 757a2af h: refs/heads/master i: 36761: 8ed6e61 36759: 652ad5c v: v3
1 parent eb66d31 commit 749a70a

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
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: eb8fd119c65c67f3b1b8268cc7341c22d39b7b61
55
refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: dd2b32be56945824e1e900d9748274633d6db6c1
8+
refs/heads/try2: 757a2afb6b80cb4dbdcb8069f1af511ec42e8670
99
refs/heads/incoming: d9317a174e434d4c99fc1a37fd7dc0d2f5328d37
1010
refs/heads/dist-snap: 22efa39382d41b084fde1719df7ae8ce5697d8c9
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596

branches/try2/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)