]> git.lizzy.rs Git - rust.git/commitdiff
core: add LinearMap::with_capacity
authorErick Tryzelaar <erick.tryzelaar@gmail.com>
Fri, 29 Mar 2013 03:30:50 +0000 (20:30 -0700)
committerErick Tryzelaar <erick.tryzelaar@gmail.com>
Fri, 29 Mar 2013 14:05:54 +0000 (07:05 -0700)
src/libcore/hashmap.rs

index 472de88f692b83bf2a1e3079bdd940a5f9498e2f..d6684b04aa373d4e35e482f0582c0aa3ff4ca564 100644 (file)
@@ -393,10 +393,16 @@ fn remove(&mut self, k: &K) -> bool {
         }
     }
 
-    pub impl<K:Hash + IterBytes + Eq,V> LinearMap<K, V> {
+    pub impl<K: Hash + IterBytes + Eq, V> LinearMap<K, V> {
         /// Create an empty LinearMap
         fn new() -> LinearMap<K, V> {
-            linear_map_with_capacity(INITIAL_CAPACITY)
+            LinearMap::with_capacity(INITIAL_CAPACITY)
+        }
+
+        /// Create an empty LinearMap with space for at least `n` elements in
+        /// the hash table.
+        fn with_capacity(capacity: uint) -> LinearMap<K, V> {
+            linear_map_with_capacity(capacity)
         }
 
         /// Reserve space for at least `n` elements in the hash table.
@@ -652,7 +658,15 @@ fn union(&self, other: &LinearSet<T>, f: &fn(&T) -> bool) {
 
     pub impl <T:Hash + IterBytes + Eq> LinearSet<T> {
         /// Create an empty LinearSet
-        fn new() -> LinearSet<T> { LinearSet{map: LinearMap::new()} }
+        fn new() -> LinearSet<T> {
+            LinearSet::with_capacity(INITIAL_CAPACITY)
+        }
+
+        /// Create an empty LinearSet with space for at least `n` elements in
+        /// the hash table.
+        fn with_capacity(capacity: uint) -> LinearSet<T> {
+            LinearSet { map: LinearMap::with_capacity(capacity) }
+        }
 
         /// Reserve space for at least `n` elements in the hash table.
         fn reserve_at_least(&mut self, n: uint) {