From 1dd11c717922fb38e87644606f9fbc9d29ee4995 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Thu, 28 Mar 2013 20:30:50 -0700 Subject: [PATCH] core: add LinearMap::with_capacity --- src/libcore/hashmap.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/libcore/hashmap.rs b/src/libcore/hashmap.rs index 472de88f692b..d6684b04aa37 100644 --- a/src/libcore/hashmap.rs +++ b/src/libcore/hashmap.rs @@ -393,10 +393,16 @@ pub mod linear { } } - pub impl LinearMap { + pub impl LinearMap { /// Create an empty LinearMap fn new() -> LinearMap { - 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 { + linear_map_with_capacity(capacity) } /// Reserve space for at least `n` elements in the hash table. @@ -652,7 +658,15 @@ pub mod linear { pub impl LinearSet { /// Create an empty LinearSet - fn new() -> LinearSet { LinearSet{map: LinearMap::new()} } + fn new() -> LinearSet { + 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 { + 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) {