Skip to content

Commit 0beaccb

Browse files
committed
Rename variables called pq to heap
The old name was sensible when this module was PriorityQueue but isn't anymore.
1 parent 2a4c010 commit 0beaccb

File tree

1 file changed

+53
-53
lines changed

1 file changed

+53
-53
lines changed

src/libcollections/binary_heap.rs

Lines changed: 53 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@
6868
//! // dist[node] = current shortest distance from `start` to `node`
6969
//! let mut dist = Vec::from_elem(adj_list.len(), uint::MAX);
7070
//!
71-
//! let mut pq = BinaryHeap::new();
71+
//! let mut heap = BinaryHeap::new();
7272
//!
7373
//! // We're at `start`, with a zero cost
7474
//! dist[start] = 0u;
75-
//! pq.push(State { cost: 0u, position: start });
75+
//! heap.push(State { cost: 0u, position: start });
7676
//!
7777
//! // Examine the frontier with lower cost nodes first (min-heap)
7878
//! loop {
79-
//! let State { cost, position } = match pq.pop() {
79+
//! let State { cost, position } = match heap.pop() {
8080
//! None => break, // empty
8181
//! Some(s) => s
8282
//! };
@@ -94,7 +94,7 @@
9494
//!
9595
//! // If so, add it to the frontier and continue
9696
//! if next.cost < dist[next.position] {
97-
//! pq.push(next);
97+
//! heap.push(next);
9898
//! // Relaxation, we have now found a better way
9999
//! dist[next.position] = next.cost;
100100
//! }
@@ -184,7 +184,7 @@ impl<T: Ord> BinaryHeap<T> {
184184
///
185185
/// ```
186186
/// use std::collections::BinaryHeap;
187-
/// let pq: BinaryHeap<uint> = BinaryHeap::new();
187+
/// let heap: BinaryHeap<uint> = BinaryHeap::new();
188188
/// ```
189189
#[unstable = "matches collection reform specification, waiting for dust to settle"]
190190
pub fn new() -> BinaryHeap<T> { BinaryHeap{data: vec!(),} }
@@ -198,7 +198,7 @@ impl<T: Ord> BinaryHeap<T> {
198198
///
199199
/// ```
200200
/// use std::collections::BinaryHeap;
201-
/// let pq: BinaryHeap<uint> = BinaryHeap::with_capacity(10u);
201+
/// let heap: BinaryHeap<uint> = BinaryHeap::with_capacity(10u);
202202
/// ```
203203
#[unstable = "matches collection reform specification, waiting for dust to settle"]
204204
pub fn with_capacity(capacity: uint) -> BinaryHeap<T> {
@@ -212,7 +212,7 @@ impl<T: Ord> BinaryHeap<T> {
212212
///
213213
/// ```
214214
/// use std::collections::BinaryHeap;
215-
/// let pq = BinaryHeap::from_vec(vec![9i, 1, 2, 7, 3, 2]);
215+
/// let heap = BinaryHeap::from_vec(vec![9i, 1, 2, 7, 3, 2]);
216216
/// ```
217217
pub fn from_vec(xs: Vec<T>) -> BinaryHeap<T> {
218218
let mut q = BinaryHeap{data: xs,};
@@ -231,10 +231,10 @@ impl<T: Ord> BinaryHeap<T> {
231231
///
232232
/// ```
233233
/// use std::collections::BinaryHeap;
234-
/// let pq = BinaryHeap::from_vec(vec![1i, 2, 3, 4]);
234+
/// let heap = BinaryHeap::from_vec(vec![1i, 2, 3, 4]);
235235
///
236236
/// // Print 1, 2, 3, 4 in arbitrary order
237-
/// for x in pq.iter() {
237+
/// for x in heap.iter() {
238238
/// println!("{}", x);
239239
/// }
240240
/// ```
@@ -250,13 +250,13 @@ impl<T: Ord> BinaryHeap<T> {
250250
/// ```
251251
/// use std::collections::BinaryHeap;
252252
///
253-
/// let mut pq = BinaryHeap::new();
254-
/// assert_eq!(pq.top(), None);
253+
/// let mut heap = BinaryHeap::new();
254+
/// assert_eq!(heap.top(), None);
255255
///
256-
/// pq.push(1i);
257-
/// pq.push(5i);
258-
/// pq.push(2i);
259-
/// assert_eq!(pq.top(), Some(&5i));
256+
/// heap.push(1i);
257+
/// heap.push(5i);
258+
/// heap.push(2i);
259+
/// assert_eq!(heap.top(), Some(&5i));
260260
///
261261
/// ```
262262
pub fn top<'a>(&'a self) -> Option<&'a T> {
@@ -270,8 +270,8 @@ impl<T: Ord> BinaryHeap<T> {
270270
/// ```
271271
/// use std::collections::BinaryHeap;
272272
///
273-
/// let pq: BinaryHeap<uint> = BinaryHeap::with_capacity(100u);
274-
/// assert!(pq.capacity() >= 100u);
273+
/// let heap: BinaryHeap<uint> = BinaryHeap::with_capacity(100u);
274+
/// assert!(heap.capacity() >= 100u);
275275
/// ```
276276
#[unstable = "matches collection reform specification, waiting for dust to settle"]
277277
pub fn capacity(&self) -> uint { self.data.capacity() }
@@ -292,9 +292,9 @@ impl<T: Ord> BinaryHeap<T> {
292292
/// ```
293293
/// use std::collections::BinaryHeap;
294294
///
295-
/// let mut pq: BinaryHeap<uint> = BinaryHeap::new();
296-
/// pq.reserve_exact(100u);
297-
/// assert!(pq.capacity() >= 100u);
295+
/// let mut heap: BinaryHeap<uint> = BinaryHeap::new();
296+
/// heap.reserve_exact(100u);
297+
/// assert!(heap.capacity() >= 100u);
298298
/// ```
299299
#[unstable = "matches collection reform specification, waiting for dust to settle"]
300300
pub fn reserve_exact(&mut self, additional: uint) { self.data.reserve_exact(additional) }
@@ -311,9 +311,9 @@ impl<T: Ord> BinaryHeap<T> {
311311
/// ```
312312
/// use std::collections::BinaryHeap;
313313
///
314-
/// let mut pq: BinaryHeap<uint> = BinaryHeap::new();
315-
/// pq.reserve(100u);
316-
/// assert!(pq.capacity() >= 100u);
314+
/// let mut heap: BinaryHeap<uint> = BinaryHeap::new();
315+
/// heap.reserve(100u);
316+
/// assert!(heap.capacity() >= 100u);
317317
/// ```
318318
#[unstable = "matches collection reform specification, waiting for dust to settle"]
319319
pub fn reserve(&mut self, additional: uint) {
@@ -334,11 +334,11 @@ impl<T: Ord> BinaryHeap<T> {
334334
/// ```
335335
/// use std::collections::BinaryHeap;
336336
///
337-
/// let mut pq = BinaryHeap::from_vec(vec![1i, 3]);
337+
/// let mut heap = BinaryHeap::from_vec(vec![1i, 3]);
338338
///
339-
/// assert_eq!(pq.pop(), Some(3i));
340-
/// assert_eq!(pq.pop(), Some(1i));
341-
/// assert_eq!(pq.pop(), None);
339+
/// assert_eq!(heap.pop(), Some(3i));
340+
/// assert_eq!(heap.pop(), Some(1i));
341+
/// assert_eq!(heap.pop(), None);
342342
/// ```
343343
#[unstable = "matches collection reform specification, waiting for dust to settle"]
344344
pub fn pop(&mut self) -> Option<T> {
@@ -361,13 +361,13 @@ impl<T: Ord> BinaryHeap<T> {
361361
/// ```
362362
/// use std::collections::BinaryHeap;
363363
///
364-
/// let mut pq = BinaryHeap::new();
365-
/// pq.push(3i);
366-
/// pq.push(5i);
367-
/// pq.push(1i);
364+
/// let mut heap = BinaryHeap::new();
365+
/// heap.push(3i);
366+
/// heap.push(5i);
367+
/// heap.push(1i);
368368
///
369-
/// assert_eq!(pq.len(), 3);
370-
/// assert_eq!(pq.top(), Some(&5i));
369+
/// assert_eq!(heap.len(), 3);
370+
/// assert_eq!(heap.top(), Some(&5i));
371371
/// ```
372372
#[unstable = "matches collection reform specification, waiting for dust to settle"]
373373
pub fn push(&mut self, item: T) {
@@ -384,14 +384,14 @@ impl<T: Ord> BinaryHeap<T> {
384384
/// ```
385385
/// use std::collections::BinaryHeap;
386386
///
387-
/// let mut pq = BinaryHeap::new();
388-
/// pq.push(1i);
389-
/// pq.push(5i);
387+
/// let mut heap = BinaryHeap::new();
388+
/// heap.push(1i);
389+
/// heap.push(5i);
390390
///
391-
/// assert_eq!(pq.push_pop(3i), 5);
392-
/// assert_eq!(pq.push_pop(9i), 9);
393-
/// assert_eq!(pq.len(), 2);
394-
/// assert_eq!(pq.top(), Some(&3i));
391+
/// assert_eq!(heap.push_pop(3i), 5);
392+
/// assert_eq!(heap.push_pop(9i), 9);
393+
/// assert_eq!(heap.len(), 2);
394+
/// assert_eq!(heap.top(), Some(&3i));
395395
/// ```
396396
pub fn push_pop(&mut self, mut item: T) -> T {
397397
if !self.is_empty() && *self.top().unwrap() > item {
@@ -410,12 +410,12 @@ impl<T: Ord> BinaryHeap<T> {
410410
/// ```
411411
/// use std::collections::BinaryHeap;
412412
///
413-
/// let mut pq = BinaryHeap::new();
413+
/// let mut heap = BinaryHeap::new();
414414
///
415-
/// assert_eq!(pq.replace(1i), None);
416-
/// assert_eq!(pq.replace(3i), Some(1i));
417-
/// assert_eq!(pq.len(), 1);
418-
/// assert_eq!(pq.top(), Some(&3i));
415+
/// assert_eq!(heap.replace(1i), None);
416+
/// assert_eq!(heap.replace(3i), Some(1i));
417+
/// assert_eq!(heap.len(), 1);
418+
/// assert_eq!(heap.top(), Some(&3i));
419419
/// ```
420420
pub fn replace(&mut self, mut item: T) -> Option<T> {
421421
if !self.is_empty() {
@@ -436,8 +436,8 @@ impl<T: Ord> BinaryHeap<T> {
436436
/// ```
437437
/// use std::collections::BinaryHeap;
438438
///
439-
/// let pq = BinaryHeap::from_vec(vec![1i, 2, 3, 4, 5, 6, 7]);
440-
/// let vec = pq.into_vec();
439+
/// let heap = BinaryHeap::from_vec(vec![1i, 2, 3, 4, 5, 6, 7]);
440+
/// let vec = heap.into_vec();
441441
///
442442
/// // Will print in some order
443443
/// for x in vec.iter() {
@@ -454,11 +454,11 @@ impl<T: Ord> BinaryHeap<T> {
454454
/// ```
455455
/// use std::collections::BinaryHeap;
456456
///
457-
/// let mut pq = BinaryHeap::from_vec(vec![1i, 2, 4, 5, 7]);
458-
/// pq.push(6);
459-
/// pq.push(3);
457+
/// let mut heap = BinaryHeap::from_vec(vec![1i, 2, 4, 5, 7]);
458+
/// heap.push(6);
459+
/// heap.push(3);
460460
///
461-
/// let vec = pq.into_sorted_vec();
461+
/// let vec = heap.into_sorted_vec();
462462
/// assert_eq!(vec, vec![1i, 2, 3, 4, 5, 6, 7]);
463463
/// ```
464464
pub fn into_sorted_vec(self) -> Vec<T> {
@@ -578,9 +578,9 @@ mod tests {
578578
fn test_iterator() {
579579
let data = vec!(5i, 9, 3);
580580
let iterout = [9i, 5, 3];
581-
let pq = BinaryHeap::from_vec(data);
581+
let heap = BinaryHeap::from_vec(data);
582582
let mut i = 0;
583-
for el in pq.iter() {
583+
for el in heap.iter() {
584584
assert_eq!(*el, iterout[i]);
585585
i += 1;
586586
}

0 commit comments

Comments
 (0)