diff options
| author | Erick Tryzelaar <erick.tryzelaar@gmail.com> | 2014-04-03 20:47:53 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2014-04-04 13:23:07 -0700 |
| commit | 58ac1c3563679b51f0e6dae1188cb635f1e89292 (patch) | |
| tree | 91c32127dd37091647671837cec6bad5c1b264c7 | |
| parent | 8057faa2d320db0abdfb385ad1827f8902931cef (diff) | |
| download | rust-58ac1c3563679b51f0e6dae1188cb635f1e89292.tar.gz rust-58ac1c3563679b51f0e6dae1188cb635f1e89292.zip | |
extra: Add with_capacity to PriorityQueue and SmallIntMap
| -rw-r--r-- | src/libcollections/priority_queue.rs | 5 | ||||
| -rw-r--r-- | src/libcollections/smallintmap.rs | 5 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/libcollections/priority_queue.rs b/src/libcollections/priority_queue.rs index 8c7eb1c6033..a13785104ab 100644 --- a/src/libcollections/priority_queue.rs +++ b/src/libcollections/priority_queue.rs @@ -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,}; diff --git a/src/libcollections/smallintmap.rs b/src/libcollections/smallintmap.rs index db7fafe522b..bd4f85aa81a 100644 --- a/src/libcollections/smallintmap.rs +++ b/src/libcollections/smallintmap.rs @@ -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") } |
