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) {