Skip to content

Commit

Permalink
rustfmt libcollections
Browse files Browse the repository at this point in the history
  • Loading branch information
nrc committed Nov 23, 2015
1 parent 1f1a1e6 commit 0dfd875
Show file tree
Hide file tree
Showing 14 changed files with 1,426 additions and 982 deletions.
94 changes: 66 additions & 28 deletions src/libcollections/binary_heap.rs
Expand Up @@ -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;
Expand Down Expand Up @@ -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")]
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -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;
}
Expand All @@ -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.
///
Expand All @@ -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
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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>,
}

Expand All @@ -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")]
Expand All @@ -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")]
Expand All @@ -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")]
Expand Down Expand Up @@ -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<_>>())
}
}
Expand Down Expand Up @@ -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();

Expand All @@ -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());
}
}
48 changes: 27 additions & 21 deletions src/libcollections/borrow.rs
Expand Up @@ -28,7 +28,10 @@ use self::Cow::*;
pub use core::borrow::{Borrow, BorrowMut};

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B> where B: ToOwned, <B as ToOwned>::Owned: 'a {
impl<'a, B: ?Sized> Borrow<B> for Cow<'a, B>
where B: ToOwned,
<B as ToOwned>::Owned: 'a
{
fn borrow(&self) -> &B {
&**self
}
Expand All @@ -53,7 +56,9 @@ pub trait ToOwned {
#[stable(feature = "rust1", since = "1.0.0")]
impl<T> ToOwned for T where T: Clone {
type Owned = T;
fn to_owned(&self) -> T { self.clone() }
fn to_owned(&self) -> T {
self.clone()
}
}

/// A clone-on-write smart pointer.
Expand Down Expand Up @@ -85,14 +90,16 @@ impl<T> ToOwned for T where T: Clone {
/// }
/// ```
#[stable(feature = "rust1", since = "1.0.0")]
pub enum Cow<'a, B: ?Sized + 'a> where B: ToOwned {
pub enum Cow<'a, B: ?Sized + 'a>
where B: ToOwned
{
/// Borrowed data.
#[stable(feature = "rust1", since = "1.0.0")]
Borrowed(&'a B),

/// Owned data.
#[stable(feature = "rust1", since = "1.0.0")]
Owned(<B as ToOwned>::Owned)
Owned(<B as ToOwned>::Owned),
}

#[stable(feature = "rust1", since = "1.0.0")]
Expand All @@ -103,7 +110,7 @@ impl<'a, B: ?Sized> Clone for Cow<'a, B> where B: ToOwned {
Owned(ref o) => {
let b: &B = o.borrow();
Owned(b.to_owned())
},
}
}
}
}
Expand Down Expand Up @@ -131,7 +138,7 @@ impl<'a, B: ?Sized> Cow<'a, B> where B: ToOwned {
*self = Owned(borrowed.to_owned());
self.to_mut()
}
Owned(ref mut owned) => owned
Owned(ref mut owned) => owned,
}
}

Expand All @@ -154,7 +161,7 @@ impl<'a, B: ?Sized> Cow<'a, B> where B: ToOwned {
pub fn into_owned(self) -> <B as ToOwned>::Owned {
match self {
Borrowed(borrowed) => borrowed.to_owned(),
Owned(owned) => owned
Owned(owned) => owned,
}
}
}
Expand All @@ -166,7 +173,7 @@ impl<'a, B: ?Sized> Deref for Cow<'a, B> where B: ToOwned {
fn deref(&self) -> &B {
match *self {
Borrowed(borrowed) => borrowed,
Owned(ref owned) => owned.borrow()
Owned(ref owned) => owned.borrow(),
}
}
}
Expand All @@ -183,8 +190,9 @@ impl<'a, B: ?Sized> Ord for Cow<'a, B> where B: Ord + ToOwned {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, C>> for Cow<'a, B> where
B: PartialEq<C> + ToOwned, C: ToOwned,
impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, C>> for Cow<'a, B>
where B: PartialEq<C> + ToOwned,
C: ToOwned
{
#[inline]
fn eq(&self, other: &Cow<'b, C>) -> bool {
Expand All @@ -193,18 +201,17 @@ impl<'a, 'b, B: ?Sized, C: ?Sized> PartialEq<Cow<'b, C>> for Cow<'a, B> where
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> PartialOrd for Cow<'a, B> where B: PartialOrd + ToOwned,
{
impl<'a, B: ?Sized> PartialOrd for Cow<'a, B> where B: PartialOrd + ToOwned {
#[inline]
fn partial_cmp(&self, other: &Cow<'a, B>) -> Option<Ordering> {
PartialOrd::partial_cmp(&**self, &**other)
}
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> fmt::Debug for Cow<'a, B> where
B: fmt::Debug + ToOwned,
<B as ToOwned>::Owned: fmt::Debug,
impl<'a, B: ?Sized> fmt::Debug for Cow<'a, B>
where B: fmt::Debug + ToOwned,
<B as ToOwned>::Owned: fmt::Debug
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Expand All @@ -215,9 +222,9 @@ impl<'a, B: ?Sized> fmt::Debug for Cow<'a, B> where
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> fmt::Display for Cow<'a, B> where
B: fmt::Display + ToOwned,
<B as ToOwned>::Owned: fmt::Display,
impl<'a, B: ?Sized> fmt::Display for Cow<'a, B>
where B: fmt::Display + ToOwned,
<B as ToOwned>::Owned: fmt::Display
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Expand All @@ -228,8 +235,7 @@ impl<'a, B: ?Sized> fmt::Display for Cow<'a, B> where
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> Hash for Cow<'a, B> where B: Hash + ToOwned
{
impl<'a, B: ?Sized> Hash for Cow<'a, B> where B: Hash + ToOwned {
#[inline]
fn hash<H: Hasher>(&self, state: &mut H) {
Hash::hash(&**self, state)
Expand All @@ -245,7 +251,7 @@ pub trait IntoCow<'a, B: ?Sized> where B: ToOwned {
}

#[stable(feature = "rust1", since = "1.0.0")]
impl<'a, B: ?Sized> IntoCow<'a, B> for Cow<'a, B> where B: ToOwned {
impl<'a, B: ?Sized> IntoCow<'a, B> for Cow<'a, B> where B: ToOwned {
fn into_cow(self) -> Cow<'a, B> {
self
}
Expand Down

0 comments on commit 0dfd875

Please sign in to comment.