about summary refs log tree commit diff
diff options
context:
space:
mode:
authorErick Tryzelaar <erick.tryzelaar@gmail.com>2014-04-03 20:47:53 -0700
committerAlex Crichton <alex@alexcrichton.com>2014-04-04 13:23:07 -0700
commit58ac1c3563679b51f0e6dae1188cb635f1e89292 (patch)
tree91c32127dd37091647671837cec6bad5c1b264c7
parent8057faa2d320db0abdfb385ad1827f8902931cef (diff)
downloadrust-58ac1c3563679b51f0e6dae1188cb635f1e89292.tar.gz
rust-58ac1c3563679b51f0e6dae1188cb635f1e89292.zip
extra: Add with_capacity to PriorityQueue and SmallIntMap
-rw-r--r--src/libcollections/priority_queue.rs5
-rw-r--r--src/libcollections/smallintmap.rs5
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")
     }