Skip to content

Commit

Permalink
extra: Add with_capacity to PriorityQueue and SmallIntMap
Browse files Browse the repository at this point in the history
  • Loading branch information
erickt authored and alexcrichton committed Apr 4, 2014
1 parent 8057faa commit 58ac1c3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/libcollections/priority_queue.rs
Expand Up @@ -117,6 +117,11 @@ impl<T:Ord> PriorityQueue<T> {
/// Create an empty PriorityQueue
pub fn new() -> PriorityQueue<T> { PriorityQueue{data: ~[],} }

/// Create an empty PriorityQueue with capacity `capacity`
pub fn with_capacity(capacity: uint) -> PriorityQueue<T> {
PriorityQueue { data: slice::with_capacity(capacity) }
}

/// Create a PriorityQueue from a vector (heapify)
pub fn from_vec(xs: ~[T]) -> PriorityQueue<T> {
let mut q = PriorityQueue{data: xs,};
Expand Down
5 changes: 5 additions & 0 deletions src/libcollections/smallintmap.rs
Expand Up @@ -112,6 +112,11 @@ impl<V> SmallIntMap<V> {
/// Create an empty SmallIntMap
pub fn new() -> SmallIntMap<V> { SmallIntMap{v: ~[]} }

/// Create an empty SmallIntMap with capacity `capacity`
pub fn with_capacity(capacity: uint) -> SmallIntMap<V> {
SmallIntMap { v: slice::with_capacity(capacity) }
}

pub fn get<'a>(&'a self, key: &uint) -> &'a V {
self.find(key).expect("key not present")
}
Expand Down

0 comments on commit 58ac1c3

Please sign in to comment.