Skip to content

Commit

Permalink
collections: Add missing Default impls
Browse files Browse the repository at this point in the history
Add Default impls for TreeMap, TreeSet, SmallIntMap, BitvSet, DList,
PriorityQueue, RingBuf, TrieMap, and TrieSet.
  • Loading branch information
tomjakubowski committed Jun 9, 2014
1 parent 61d65cd commit f3fef15
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/libcollections/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use core::prelude::*;

use core::cmp;
use core::default::Default;
use core::fmt;
use core::iter::{Enumerate, Repeat, Map, Zip};
use core::ops;
Expand Down Expand Up @@ -697,6 +698,11 @@ pub struct BitvSet {
bitv: BigBitv
}

impl Default for BitvSet {
#[inline]
fn default() -> BitvSet { BitvSet::new() }
}

impl BitvSet {
/// Creates a new bit vector set with initially no contents
pub fn new() -> BitvSet {
Expand Down
6 changes: 6 additions & 0 deletions src/libcollections/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use core::prelude::*;

use alloc::owned::Box;
use core::default::Default;
use core::fmt;
use core::iter;
use core::mem;
Expand Down Expand Up @@ -262,6 +263,11 @@ impl<T> Deque<T> for DList<T> {
}
}

impl<T> Default for DList<T> {
#[inline]
fn default() -> DList<T> { DList::new() }
}

impl<T> DList<T> {
/// Create an empty DList
#[inline]
Expand Down
6 changes: 6 additions & 0 deletions src/libcollections/priority_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

use core::prelude::*;

use core::default::Default;
use core::mem::{zeroed, replace, swap};
use core::ptr;

Expand All @@ -36,6 +37,11 @@ impl<T: Ord> Mutable for PriorityQueue<T> {
fn clear(&mut self) { self.data.truncate(0) }
}

impl<T: Ord> Default for PriorityQueue<T> {
#[inline]
fn default() -> PriorityQueue<T> { PriorityQueue::new() }
}

impl<T: Ord> PriorityQueue<T> {
/// An iterator visiting all values in underlying vector, in
/// arbitrary order.
Expand Down
6 changes: 6 additions & 0 deletions src/libcollections/ringbuf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use core::prelude::*;

use core::cmp;
use core::default::Default;
use core::fmt;
use core::iter::RandomAccessIterator;

Expand Down Expand Up @@ -112,6 +113,11 @@ impl<T> Deque<T> for RingBuf<T> {
}
}

impl<T> Default for RingBuf<T> {
#[inline]
fn default() -> RingBuf<T> { RingBuf::new() }
}

impl<T> RingBuf<T> {
/// Create an empty RingBuf
pub fn new() -> RingBuf<T> {
Expand Down
6 changes: 6 additions & 0 deletions src/libcollections/smallintmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

use core::prelude::*;

use core::default::Default;
use core::fmt;
use core::iter::{Enumerate, FilterMap};
use core::mem::replace;
Expand Down Expand Up @@ -113,6 +114,11 @@ impl<V> MutableMap<uint, V> for SmallIntMap<V> {
}
}

impl<V> Default for SmallIntMap<V> {
#[inline]
fn default() -> SmallIntMap<V> { SmallIntMap::new() }
}

impl<V> SmallIntMap<V> {
/// Create an empty SmallIntMap
pub fn new() -> SmallIntMap<V> { SmallIntMap{v: vec!()} }
Expand Down
11 changes: 11 additions & 0 deletions src/libcollections/treemap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use core::prelude::*;

use alloc::owned::Box;
use core::default::Default;
use core::fmt;
use core::fmt::Show;
use core::iter::Peekable;
Expand Down Expand Up @@ -134,6 +135,11 @@ impl<K: Ord, V> MutableMap<K, V> for TreeMap<K, V> {
}
}

impl<K: Ord, V> Default for TreeMap<K,V> {
#[inline]
fn default() -> TreeMap<K, V> { TreeMap::new() }
}

impl<K: Ord, V> TreeMap<K, V> {
/// Create an empty TreeMap
pub fn new() -> TreeMap<K, V> { TreeMap{root: None, length: 0} }
Expand Down Expand Up @@ -632,6 +638,11 @@ impl<T: Ord> MutableSet<T> for TreeSet<T> {
fn remove(&mut self, value: &T) -> bool { self.map.remove(value) }
}

impl<T: Ord> Default for TreeSet<T> {
#[inline]
fn default() -> TreeSet<T> { TreeSet::new() }
}

impl<T: Ord> TreeSet<T> {
/// Create an empty TreeSet
#[inline]
Expand Down
11 changes: 11 additions & 0 deletions src/libcollections/trie.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use core::prelude::*;

use alloc::owned::Box;
use core::default::Default;
use core::mem::zeroed;
use core::mem;
use core::uint;
Expand Down Expand Up @@ -104,6 +105,11 @@ impl<T> MutableMap<uint, T> for TrieMap<T> {
}
}

impl<T> Default for TrieMap<T> {
#[inline]
fn default() -> TrieMap<T> { TrieMap::new() }
}

impl<T> TrieMap<T> {
/// Create an empty TrieMap
#[inline]
Expand Down Expand Up @@ -331,6 +337,11 @@ impl MutableSet<uint> for TrieSet {
}
}

impl Default for TrieSet {
#[inline]
fn default() -> TrieSet { TrieSet::new() }
}

impl TrieSet {
/// Create an empty TrieSet
#[inline]
Expand Down

4 comments on commit f3fef15

@bors
Copy link
Contributor

@bors bors commented on f3fef15 Jun 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from huonw
at tomjakubowski@f3fef15

@bors
Copy link
Contributor

@bors bors commented on f3fef15 Jun 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging tomjakubowski/rust/default-collections = f3fef15 into auto

@bors
Copy link
Contributor

@bors bors commented on f3fef15 Jun 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tomjakubowski/rust/default-collections = f3fef15 merged ok, testing candidate = a6f06d7b

@bors
Copy link
Contributor

@bors bors commented on f3fef15 Jun 9, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.