diff options
| author | bors <bors@rust-lang.org> | 2014-10-31 02:27:15 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2014-10-31 02:27:15 +0000 |
| commit | 221fc1e3cdcc208e1bb7debcc2de27d47c847747 (patch) | |
| tree | 5e2d393fe5a4a94cd6a09d93f4ddcf5a4f6aecaa /src/libcollections/priority_queue.rs | |
| parent | a12d06b73fcb38cf23dfe71da725428a1094395f (diff) | |
| parent | 6fcba8826fd26028341a35d88b07208378ac05ea (diff) | |
| download | rust-221fc1e3cdcc208e1bb7debcc2de27d47c847747.tar.gz rust-221fc1e3cdcc208e1bb7debcc2de27d47c847747.zip | |
auto merge of #18459 : alexcrichton/rust/rollup, r=alexcrichton
Diffstat (limited to 'src/libcollections/priority_queue.rs')
| -rw-r--r-- | src/libcollections/priority_queue.rs | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/src/libcollections/priority_queue.rs b/src/libcollections/priority_queue.rs index 16e04b93777..65fd8ce4f54 100644 --- a/src/libcollections/priority_queue.rs +++ b/src/libcollections/priority_queue.rs @@ -71,7 +71,7 @@ //! let mut pq = PriorityQueue::new(); //! //! // We're at `start`, with a zero cost -//! *dist.get_mut(start) = 0u; +//! dist[start] = 0u; //! pq.push(State { cost: 0u, position: start }); //! //! // Examine the frontier with lower cost nodes first (min-heap) @@ -96,7 +96,7 @@ //! if next.cost < dist[next.position] { //! pq.push(next); //! // Relaxation, we have now found a better way -//! *dist.get_mut(next.position) = next.cost; +//! dist[next.position] = next.cost; //! } //! } //! } @@ -151,7 +151,7 @@ //! } //! ``` -#![allow(missing_doc)] +#![allow(missing_docs)] use core::prelude::*; @@ -330,7 +330,7 @@ impl<T: Ord> PriorityQueue<T> { None => { None } Some(mut item) => { if !self.is_empty() { - swap(&mut item, self.data.get_mut(0)); + swap(&mut item, &mut self.data[0]); self.siftdown(0); } Some(item) @@ -378,7 +378,7 @@ impl<T: Ord> PriorityQueue<T> { /// ``` pub fn push_pop(&mut self, mut item: T) -> T { if !self.is_empty() && *self.top().unwrap() > item { - swap(&mut item, self.data.get_mut(0)); + swap(&mut item, &mut self.data[0]); self.siftdown(0); } item @@ -402,7 +402,7 @@ impl<T: Ord> PriorityQueue<T> { /// ``` pub fn replace(&mut self, mut item: T) -> Option<T> { if !self.is_empty() { - swap(&mut item, self.data.get_mut(0)); + swap(&mut item, &mut self.data[0]); self.siftdown(0); Some(item) } else { @@ -462,26 +462,26 @@ impl<T: Ord> PriorityQueue<T> { // compared to using swaps, which involves twice as many moves. fn siftup(&mut self, start: uint, mut pos: uint) { unsafe { - let new = replace(self.data.get_mut(pos), zeroed()); + let new = replace(&mut self.data[pos], zeroed()); while pos > start { let parent = (pos - 1) >> 1; if new > self.data[parent] { - let x = replace(self.data.get_mut(parent), zeroed()); - ptr::write(self.data.get_mut(pos), x); + let x = replace(&mut self.data[parent], zeroed()); + ptr::write(&mut self.data[pos], x); pos = parent; continue } break } - ptr::write(self.data.get_mut(pos), new); + ptr::write(&mut self.data[pos], new); } } fn siftdown_range(&mut self, mut pos: uint, end: uint) { unsafe { let start = pos; - let new = replace(self.data.get_mut(pos), zeroed()); + let new = replace(&mut self.data[pos], zeroed()); let mut child = 2 * pos + 1; while child < end { @@ -489,13 +489,13 @@ impl<T: Ord> PriorityQueue<T> { if right < end && !(self.data[child] > self.data[right]) { child = right; } - let x = replace(self.data.get_mut(child), zeroed()); - ptr::write(self.data.get_mut(pos), x); + let x = replace(&mut self.data[child], zeroed()); + ptr::write(&mut self.data[pos], x); pos = child; child = 2 * pos + 1; } - ptr::write(self.data.get_mut(pos), new); + ptr::write(&mut self.data[pos], new); self.siftup(start, pos); } } |
