about summary refs log tree commit diff
path: root/src/libcollections/binary_heap.rs
diff options
context:
space:
mode:
authorNick Cameron <ncameron@mozilla.com>2015-11-24 11:23:48 +1300
committerNick Cameron <ncameron@mozilla.com>2015-11-24 11:53:47 +1300
commit0dfd875b6efa68ed67988a2f9856fc3bbdc91ce2 (patch)
tree4cbbfc1e2246c63f75e0d1f0e48d99153504b7b2 /src/libcollections/binary_heap.rs
parent1f1a1e6595cb9472927cd91d523982047832aa7a (diff)
downloadrust-0dfd875b6efa68ed67988a2f9856fc3bbdc91ce2.tar.gz
rust-0dfd875b6efa68ed67988a2f9856fc3bbdc91ce2.zip
rustfmt libcollections
Diffstat (limited to 'src/libcollections/binary_heap.rs')
-rw-r--r--src/libcollections/binary_heap.rs94
1 files changed, 66 insertions, 28 deletions
diff --git a/src/libcollections/binary_heap.rs b/src/libcollections/binary_heap.rs
index db555fe61aa..b643794f8a2 100644
--- a/src/libcollections/binary_heap.rs
+++ b/src/libcollections/binary_heap.rs
@@ -151,7 +151,7 @@
 #![allow(missing_docs)]
 #![stable(feature = "rust1", since = "1.0.0")]
 
-use core::iter::{FromIterator};
+use core::iter::FromIterator;
 use core::mem::swap;
 use core::ptr;
 use core::fmt;
@@ -186,7 +186,9 @@ impl<T: Clone> Clone for BinaryHeap<T> {
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Ord> Default for BinaryHeap<T> {
     #[inline]
-    fn default() -> BinaryHeap<T> { BinaryHeap::new() }
+    fn default() -> BinaryHeap<T> {
+        BinaryHeap::new()
+    }
 }
 
 #[stable(feature = "binaryheap_debug", since = "1.4.0")]
@@ -207,7 +209,9 @@ impl<T: Ord> BinaryHeap<T> {
     /// heap.push(4);
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn new() -> BinaryHeap<T> { BinaryHeap { data: vec![] } }
+    pub fn new() -> BinaryHeap<T> {
+        BinaryHeap { data: vec![] }
+    }
 
     /// Creates an empty `BinaryHeap` with a specific capacity.
     /// This preallocates enough memory for `capacity` elements,
@@ -296,7 +300,9 @@ impl<T: Ord> BinaryHeap<T> {
     /// heap.push(4);
     /// ```
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn capacity(&self) -> usize { self.data.capacity() }
+    pub fn capacity(&self) -> usize {
+        self.data.capacity()
+    }
 
     /// Reserves the minimum capacity for exactly `additional` more elements to be inserted in the
     /// given `BinaryHeap`. Does nothing if the capacity is already sufficient.
@@ -419,11 +425,13 @@ impl<T: Ord> BinaryHeap<T> {
     pub fn push_pop(&mut self, mut item: T) -> T {
         match self.data.get_mut(0) {
             None => return item,
-            Some(top) => if *top > item {
-                swap(&mut item, top);
-            } else {
-                return item;
-            },
+            Some(top) => {
+                if *top > item {
+                    swap(&mut item, top);
+                } else {
+                    return item;
+                }
+            }
         }
 
         self.sift_down(0);
@@ -522,7 +530,9 @@ impl<T: Ord> BinaryHeap<T> {
 
             while hole.pos() > start {
                 let parent = (hole.pos() - 1) / 2;
-                if hole.element() <= hole.get(parent) { break; }
+                if hole.element() <= hole.get(parent) {
+                    break;
+                }
                 hole.move_to(parent);
             }
         }
@@ -541,7 +551,9 @@ impl<T: Ord> BinaryHeap<T> {
                     child = right;
                 }
                 // if we are already in order, stop.
-                if hole.element() >= hole.get(child) { break; }
+                if hole.element() >= hole.get(child) {
+                    break;
+                }
                 hole.move_to(child);
                 child = 2 * hole.pos() + 1;
             }
@@ -555,11 +567,15 @@ impl<T: Ord> BinaryHeap<T> {
 
     /// Returns the length of the binary heap.
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn len(&self) -> usize { self.data.len() }
+    pub fn len(&self) -> usize {
+        self.data.len()
+    }
 
     /// Checks if the binary heap is empty.
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn is_empty(&self) -> bool { self.len() == 0 }
+    pub fn is_empty(&self) -> bool {
+        self.len() == 0
+    }
 
     /// Clears the binary heap, returning an iterator over the removed elements.
     ///
@@ -575,7 +591,9 @@ impl<T: Ord> BinaryHeap<T> {
 
     /// Drops all items from the binary heap.
     #[stable(feature = "rust1", since = "1.0.0")]
-    pub fn clear(&mut self) { self.drain(); }
+    pub fn clear(&mut self) {
+        self.drain();
+    }
 }
 
 /// Hole represents a hole in a slice i.e. an index without valid value
@@ -603,7 +621,9 @@ impl<'a, T> Hole<'a, T> {
     }
 
     #[inline(always)]
-    fn pos(&self) -> usize { self.pos }
+    fn pos(&self) -> usize {
+        self.pos
+    }
 
     /// Return a reference to the element removed
     #[inline(always)]
@@ -647,7 +667,7 @@ impl<'a, T> Drop for Hole<'a, T> {
 
 /// `BinaryHeap` iterator.
 #[stable(feature = "rust1", since = "1.0.0")]
-pub struct Iter <'a, T: 'a> {
+pub struct Iter<'a, T: 'a> {
     iter: slice::Iter<'a, T>,
 }
 
@@ -664,16 +684,22 @@ impl<'a, T> Iterator for Iter<'a, T> {
     type Item = &'a T;
 
     #[inline]
-    fn next(&mut self) -> Option<&'a T> { self.iter.next() }
+    fn next(&mut self) -> Option<&'a T> {
+        self.iter.next()
+    }
 
     #[inline]
-    fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        self.iter.size_hint()
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, T> DoubleEndedIterator for Iter<'a, T> {
     #[inline]
-    fn next_back(&mut self) -> Option<&'a T> { self.iter.next_back() }
+    fn next_back(&mut self) -> Option<&'a T> {
+        self.iter.next_back()
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -690,16 +716,22 @@ impl<T> Iterator for IntoIter<T> {
     type Item = T;
 
     #[inline]
-    fn next(&mut self) -> Option<T> { self.iter.next() }
+    fn next(&mut self) -> Option<T> {
+        self.iter.next()
+    }
 
     #[inline]
-    fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        self.iter.size_hint()
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T> DoubleEndedIterator for IntoIter<T> {
     #[inline]
-    fn next_back(&mut self) -> Option<T> { self.iter.next_back() }
+    fn next_back(&mut self) -> Option<T> {
+        self.iter.next_back()
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -716,16 +748,22 @@ impl<'a, T: 'a> Iterator for Drain<'a, T> {
     type Item = T;
 
     #[inline]
-    fn next(&mut self) -> Option<T> { self.iter.next() }
+    fn next(&mut self) -> Option<T> {
+        self.iter.next()
+    }
 
     #[inline]
-    fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() }
+    fn size_hint(&self) -> (usize, Option<usize>) {
+        self.iter.size_hint()
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<'a, T: 'a> DoubleEndedIterator for Drain<'a, T> {
     #[inline]
-    fn next_back(&mut self) -> Option<T> { self.iter.next_back() }
+    fn next_back(&mut self) -> Option<T> {
+        self.iter.next_back()
+    }
 }
 
 #[stable(feature = "rust1", since = "1.0.0")]
@@ -753,7 +791,7 @@ impl<T> From<BinaryHeap<T>> for Vec<T> {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Ord> FromIterator<T> for BinaryHeap<T> {
-    fn from_iter<I: IntoIterator<Item=T>>(iter: I) -> BinaryHeap<T> {
+    fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> BinaryHeap<T> {
         BinaryHeap::from(iter.into_iter().collect::<Vec<_>>())
     }
 }
@@ -796,7 +834,7 @@ impl<'a, T> IntoIterator for &'a BinaryHeap<T> where T: Ord {
 
 #[stable(feature = "rust1", since = "1.0.0")]
 impl<T: Ord> Extend<T> for BinaryHeap<T> {
-    fn extend<I: IntoIterator<Item=T>>(&mut self, iterable: I) {
+    fn extend<I: IntoIterator<Item = T>>(&mut self, iterable: I) {
         let iter = iterable.into_iter();
         let (lower, _) = iter.size_hint();
 
@@ -810,7 +848,7 @@ impl<T: Ord> Extend<T> for BinaryHeap<T> {
 
 #[stable(feature = "extend_ref", since = "1.2.0")]
 impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for BinaryHeap<T> {
-    fn extend<I: IntoIterator<Item=&'a T>>(&mut self, iter: I) {
+    fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I) {
         self.extend(iter.into_iter().cloned());
     }
 }