Skip to content

Commit 7c3db05

Browse files
committed
---
yaml --- r: 114303 b: refs/heads/master c: 44fcf46 h: refs/heads/master i: 114301: 012fcb0 114299: e6addeb 114295: ec5728e 114287: 7f05315 114271: f05c867 114239: c4ddd5f 114175: ff0da1d v: v3
1 parent 0a505c3 commit 7c3db05

File tree

8 files changed

+106
-97
lines changed

8 files changed

+106
-97
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: 564b9250362cc7bb0f40320bf2cedc58ec47b077
2+
refs/heads/master: 44fcf46b00389bea30f4902ce77f2e33557d9170
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: ec0258a381b88b5574e3f8ce72ae553ac3a574b7
55
refs/heads/try: 7c6c492fb2af9a85f21ff952942df3523b22fd17

trunk/src/doc/rust.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2943,7 +2943,7 @@ See [Break expressions](#break-expressions) and [Continue expressions](#continue
29432943
break_expr : "break" [ lifetime ];
29442944
~~~~
29452945

2946-
A `break` expression has an optional `label`.
2946+
A `break` expression has an optional _label_.
29472947
If the label is absent, then executing a `break` expression immediately terminates the innermost loop enclosing it.
29482948
It is only permitted in the body of a loop.
29492949
If the label is present, then `break foo` terminates the loop with label `foo`,
@@ -2956,7 +2956,7 @@ but must enclose it.
29562956
continue_expr : "continue" [ lifetime ];
29572957
~~~~
29582958

2959-
A `continue` expression has an optional `label`.
2959+
A `continue` expression has an optional _label_.
29602960
If the label is absent,
29612961
then executing a `continue` expression immediately terminates the current iteration of the innermost loop enclosing it,
29622962
returning control to the loop *head*.
@@ -3115,7 +3115,7 @@ let x: List<int> = Cons(10, box Cons(11, box Nil));
31153115
31163116
match x {
31173117
Cons(a, box Cons(b, _)) => {
3118-
process_pair(a,b);
3118+
process_pair(a, b);
31193119
}
31203120
Cons(10, _) => {
31213121
process_ten();
@@ -3329,8 +3329,8 @@ order specified by the tuple type.
33293329
An example of a tuple type and its use:
33303330

33313331
~~~~
3332-
type Pair<'a> = (int,&'a str);
3333-
let p: Pair<'static> = (10,"hello");
3332+
type Pair<'a> = (int, &'a str);
3333+
let p: Pair<'static> = (10, "hello");
33343334
let (a, b) = p;
33353335
assert!(b != "world");
33363336
~~~~

trunk/src/doc/tutorial.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2602,7 +2602,7 @@ fn main() {
26022602
~~~
26032603

26042604
The full list of derivable traits is `Eq`, `TotalEq`, `Ord`,
2605-
`TotalOrd`, `Encodable` `Decodable`, `Clone`,
2605+
`TotalOrd`, `Encodable`, `Decodable`, `Clone`,
26062606
`Hash`, `Rand`, `Default`, `Zero`, `FromPrimitive` and `Show`.
26072607

26082608
# Crates and the module system

trunk/src/libcollections/dlist.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,7 @@ impl<T> DList<T> {
410410
}
411411
}
412412

413-
impl<T: Ord> DList<T> {
413+
impl<T: TotalOrd> DList<T> {
414414
/// Insert `elt` sorted in ascending order
415415
///
416416
/// O(N)

trunk/src/libcollections/priority_queue.rs

Lines changed: 72 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,31 @@ pub struct PriorityQueue<T> {
2222
data: Vec<T>,
2323
}
2424

25-
impl<T:Ord> Container for PriorityQueue<T> {
25+
impl<T: TotalOrd> Container for PriorityQueue<T> {
2626
/// Returns the length of the queue
2727
fn len(&self) -> uint { self.data.len() }
2828
}
2929

30-
impl<T:Ord> Mutable for PriorityQueue<T> {
30+
impl<T: TotalOrd> Mutable for PriorityQueue<T> {
3131
/// Drop all items from the queue
3232
fn clear(&mut self) { self.data.truncate(0) }
3333
}
3434

35-
impl<T:Ord> PriorityQueue<T> {
35+
impl<T: TotalOrd> PriorityQueue<T> {
3636
/// An iterator visiting all values in underlying vector, in
3737
/// arbitrary order.
3838
pub fn iter<'a>(&'a self) -> Items<'a, T> {
3939
Items { iter: self.data.iter() }
4040
}
4141

42-
/// Returns the greatest item in the queue - fails if empty
43-
pub fn top<'a>(&'a self) -> &'a T { self.data.get(0) }
44-
45-
/// Returns the greatest item in the queue - None if empty
46-
pub fn maybe_top<'a>(&'a self) -> Option<&'a T> {
47-
if self.is_empty() { None } else { Some(self.top()) }
42+
/// Returns the greatest item in a queue or None if it is empty
43+
pub fn top<'a>(&'a self) -> Option<&'a T> {
44+
if self.is_empty() { None } else { Some(self.data.get(0)) }
4845
}
4946

47+
#[deprecated="renamed to `top`"]
48+
pub fn maybe_top<'a>(&'a self) -> Option<&'a T> { self.top() }
49+
5050
/// Returns the number of elements the queue can hold without reallocating
5151
pub fn capacity(&self) -> uint { self.data.capacity() }
5252

@@ -60,20 +60,23 @@ impl<T:Ord> PriorityQueue<T> {
6060
self.data.reserve(n)
6161
}
6262

63-
/// Pop the greatest item from the queue - fails if empty
64-
pub fn pop(&mut self) -> T {
65-
let mut item = self.data.pop().unwrap();
66-
if !self.is_empty() {
67-
swap(&mut item, self.data.get_mut(0));
68-
self.siftdown(0);
63+
/// Remove the greatest item from a queue and return it, or `None` if it is
64+
/// empty.
65+
pub fn pop(&mut self) -> Option<T> {
66+
match self.data.pop() {
67+
None => { None }
68+
Some(mut item) => {
69+
if !self.is_empty() {
70+
swap(&mut item, self.data.get_mut(0));
71+
self.siftdown(0);
72+
}
73+
Some(item)
74+
}
6975
}
70-
item
7176
}
7277

73-
/// Pop the greatest item from the queue - None if empty
74-
pub fn maybe_pop(&mut self) -> Option<T> {
75-
if self.is_empty() { None } else { Some(self.pop()) }
76-
}
78+
#[deprecated="renamed to `pop`"]
79+
pub fn maybe_pop(&mut self) -> Option<T> { self.pop() }
7780

7881
/// Push an item onto the queue
7982
pub fn push(&mut self, item: T) {
@@ -84,34 +87,48 @@ impl<T:Ord> PriorityQueue<T> {
8487

8588
/// Optimized version of a push followed by a pop
8689
pub fn push_pop(&mut self, mut item: T) -> T {
87-
if !self.is_empty() && *self.top() > item {
90+
if !self.is_empty() && *self.top().unwrap() > item {
8891
swap(&mut item, self.data.get_mut(0));
8992
self.siftdown(0);
9093
}
9194
item
9295
}
9396

94-
/// Optimized version of a pop followed by a push - fails if empty
95-
pub fn replace(&mut self, mut item: T) -> T {
96-
swap(&mut item, self.data.get_mut(0));
97-
self.siftdown(0);
98-
item
97+
/// Optimized version of a pop followed by a push. The push is done
98+
/// regardless of whether the queue is empty.
99+
pub fn replace(&mut self, mut item: T) -> Option<T> {
100+
if !self.is_empty() {
101+
swap(&mut item, self.data.get_mut(0));
102+
self.siftdown(0);
103+
Some(item)
104+
} else {
105+
self.push(item);
106+
None
107+
}
99108
}
100109

110+
#[allow(dead_code)]
111+
#[deprecated="renamed to `into_vec`"]
112+
fn to_vec(self) -> Vec<T> { self.into_vec() }
113+
114+
#[allow(dead_code)]
115+
#[deprecated="renamed to `into_sorted_vec`"]
116+
fn to_sorted_vec(self) -> Vec<T> { self.into_sorted_vec() }
117+
101118
/// Consume the PriorityQueue and return the underlying vector
102-
pub fn to_vec(self) -> Vec<T> { let PriorityQueue{data: v} = self; v }
119+
pub fn into_vec(self) -> Vec<T> { let PriorityQueue{data: v} = self; v }
103120

104121
/// Consume the PriorityQueue and return a vector in sorted
105122
/// (ascending) order
106-
pub fn to_sorted_vec(self) -> Vec<T> {
123+
pub fn into_sorted_vec(self) -> Vec<T> {
107124
let mut q = self;
108125
let mut end = q.len();
109126
while end > 1 {
110127
end -= 1;
111128
q.data.as_mut_slice().swap(0, end);
112129
q.siftdown_range(0, end)
113130
}
114-
q.to_vec()
131+
q.into_vec()
115132
}
116133

117134
/// Create an empty PriorityQueue
@@ -197,15 +214,15 @@ impl<'a, T> Iterator<&'a T> for Items<'a, T> {
197214
fn size_hint(&self) -> (uint, Option<uint>) { self.iter.size_hint() }
198215
}
199216

200-
impl<T: Ord> FromIterator<T> for PriorityQueue<T> {
217+
impl<T: TotalOrd> FromIterator<T> for PriorityQueue<T> {
201218
fn from_iter<Iter: Iterator<T>>(iter: Iter) -> PriorityQueue<T> {
202219
let mut q = PriorityQueue::new();
203220
q.extend(iter);
204221
q
205222
}
206223
}
207224

208-
impl<T: Ord> Extendable<T> for PriorityQueue<T> {
225+
impl<T: TotalOrd> Extendable<T> for PriorityQueue<T> {
209226
fn extend<Iter: Iterator<T>>(&mut self, mut iter: Iter) {
210227
let (lower, _) = iter.size_hint();
211228

@@ -241,53 +258,53 @@ mod tests {
241258
sorted.sort();
242259
let mut heap = PriorityQueue::from_vec(data);
243260
while !heap.is_empty() {
244-
assert_eq!(heap.top(), sorted.last().unwrap());
245-
assert_eq!(heap.pop(), sorted.pop().unwrap());
261+
assert_eq!(heap.top().unwrap(), sorted.last().unwrap());
262+
assert_eq!(heap.pop().unwrap(), sorted.pop().unwrap());
246263
}
247264
}
248265

249266
#[test]
250267
fn test_push() {
251268
let mut heap = PriorityQueue::from_vec(vec!(2, 4, 9));
252269
assert_eq!(heap.len(), 3);
253-
assert!(*heap.top() == 9);
270+
assert!(*heap.top().unwrap() == 9);
254271
heap.push(11);
255272
assert_eq!(heap.len(), 4);
256-
assert!(*heap.top() == 11);
273+
assert!(*heap.top().unwrap() == 11);
257274
heap.push(5);
258275
assert_eq!(heap.len(), 5);
259-
assert!(*heap.top() == 11);
276+
assert!(*heap.top().unwrap() == 11);
260277
heap.push(27);
261278
assert_eq!(heap.len(), 6);
262-
assert!(*heap.top() == 27);
279+
assert!(*heap.top().unwrap() == 27);
263280
heap.push(3);
264281
assert_eq!(heap.len(), 7);
265-
assert!(*heap.top() == 27);
282+
assert!(*heap.top().unwrap() == 27);
266283
heap.push(103);
267284
assert_eq!(heap.len(), 8);
268-
assert!(*heap.top() == 103);
285+
assert!(*heap.top().unwrap() == 103);
269286
}
270287

271288
#[test]
272289
fn test_push_unique() {
273290
let mut heap = PriorityQueue::from_vec(vec!(box 2, box 4, box 9));
274291
assert_eq!(heap.len(), 3);
275-
assert!(*heap.top() == box 9);
292+
assert!(*heap.top().unwrap() == box 9);
276293
heap.push(box 11);
277294
assert_eq!(heap.len(), 4);
278-
assert!(*heap.top() == box 11);
295+
assert!(*heap.top().unwrap() == box 11);
279296
heap.push(box 5);
280297
assert_eq!(heap.len(), 5);
281-
assert!(*heap.top() == box 11);
298+
assert!(*heap.top().unwrap() == box 11);
282299
heap.push(box 27);
283300
assert_eq!(heap.len(), 6);
284-
assert!(*heap.top() == box 27);
301+
assert!(*heap.top().unwrap() == box 27);
285302
heap.push(box 3);
286303
assert_eq!(heap.len(), 7);
287-
assert!(*heap.top() == box 27);
304+
assert!(*heap.top().unwrap() == box 27);
288305
heap.push(box 103);
289306
assert_eq!(heap.len(), 8);
290-
assert!(*heap.top() == box 103);
307+
assert!(*heap.top().unwrap() == box 103);
291308
}
292309

293310
#[test]
@@ -308,24 +325,24 @@ mod tests {
308325
fn test_replace() {
309326
let mut heap = PriorityQueue::from_vec(vec!(5, 5, 2, 1, 3));
310327
assert_eq!(heap.len(), 5);
311-
assert_eq!(heap.replace(6), 5);
328+
assert_eq!(heap.replace(6).unwrap(), 5);
312329
assert_eq!(heap.len(), 5);
313-
assert_eq!(heap.replace(0), 6);
330+
assert_eq!(heap.replace(0).unwrap(), 6);
314331
assert_eq!(heap.len(), 5);
315-
assert_eq!(heap.replace(4), 5);
332+
assert_eq!(heap.replace(4).unwrap(), 5);
316333
assert_eq!(heap.len(), 5);
317-
assert_eq!(heap.replace(1), 4);
334+
assert_eq!(heap.replace(1).unwrap(), 4);
318335
assert_eq!(heap.len(), 5);
319336
}
320337

321338
fn check_to_vec(mut data: Vec<int>) {
322339
let heap = PriorityQueue::from_vec(data.clone());
323-
let mut v = heap.clone().to_vec();
340+
let mut v = heap.clone().into_vec();
324341
v.sort();
325342
data.sort();
326343

327344
assert_eq!(v, data);
328-
assert_eq!(heap.to_sorted_vec(), data);
345+
assert_eq!(heap.into_sorted_vec(), data);
329346
}
330347

331348
#[test]
@@ -346,36 +363,21 @@ mod tests {
346363
}
347364

348365
#[test]
349-
#[should_fail]
350366
fn test_empty_pop() {
351367
let mut heap: PriorityQueue<int> = PriorityQueue::new();
352-
heap.pop();
353-
}
354-
355-
#[test]
356-
fn test_empty_maybe_pop() {
357-
let mut heap: PriorityQueue<int> = PriorityQueue::new();
358-
assert!(heap.maybe_pop().is_none());
368+
assert!(heap.pop().is_none());
359369
}
360370

361371
#[test]
362-
#[should_fail]
363372
fn test_empty_top() {
364373
let empty: PriorityQueue<int> = PriorityQueue::new();
365-
empty.top();
366-
}
367-
368-
#[test]
369-
fn test_empty_maybe_top() {
370-
let empty: PriorityQueue<int> = PriorityQueue::new();
371-
assert!(empty.maybe_top().is_none());
374+
assert!(empty.top().is_none());
372375
}
373376

374377
#[test]
375-
#[should_fail]
376378
fn test_empty_replace() {
377379
let mut heap: PriorityQueue<int> = PriorityQueue::new();
378-
heap.replace(5);
380+
heap.replace(5).is_none();
379381
}
380382

381383
#[test]
@@ -385,7 +387,7 @@ mod tests {
385387
let mut q: PriorityQueue<uint> = xs.as_slice().iter().rev().map(|&x| x).collect();
386388

387389
for &x in xs.iter() {
388-
assert_eq!(q.pop(), x);
390+
assert_eq!(q.pop().unwrap(), x);
389391
}
390392
}
391393
}

trunk/src/libcore/bool.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,14 @@
1515
//! Implementations of the following traits:
1616
//!
1717
//! * `Not`
18+
//! * `BitAnd`
19+
//! * `BitOr`
20+
//! * `BitXor`
1821
//! * `Ord`
1922
//! * `TotalOrd`
2023
//! * `Eq`
24+
//! * `TotalEq`
2125
//! * `Default`
22-
//! * `Zero`
2326
//!
2427
//! A `to_bit` conversion function.
2528

0 commit comments

Comments
 (0)