diff options
| author | Florian Hahn <flo@fhahn.com> | 2013-09-11 00:39:26 +0200 |
|---|---|---|
| committer | Florian Hahn <flo@fhahn.com> | 2013-09-11 16:57:15 +0200 |
| commit | b0e13e0d0e61b4147c8c62856c50cf727f7c918f (patch) | |
| tree | bbe5ba14522ff90048821c3ac5f255859442391b /src/libstd | |
| parent | 67ed30cd5eab9af1976a994c50d146a3dbeccad4 (diff) | |
| download | rust-b0e13e0d0e61b4147c8c62856c50cf727f7c918f.tar.gz rust-b0e13e0d0e61b4147c8c62856c50cf727f7c918f.zip | |
Add HashSet::with_capacity_and_keys() function
This function can be use to create HashSets before the tls is initialized.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/hashmap.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/libstd/hashmap.rs b/src/libstd/hashmap.rs index fab8299f7a7..09f0af00417 100644 --- a/src/libstd/hashmap.rs +++ b/src/libstd/hashmap.rs @@ -687,6 +687,17 @@ impl<T:Hash + Eq> HashSet<T> { HashSet { map: HashMap::with_capacity(capacity) } } + /// Create an empty HashSet with space for at least `capacity` + /// elements in the hash table, using `k0` and `k1` as the keys. + /// + /// Warning: `k0` and `k1` are normally randomly generated, and + /// are designed to allow HashSets to be resistant to attacks that + /// cause many collisions and very poor performance. Setting them + /// manually using this function can expose a DoS attack vector. + pub fn with_capacity_and_keys(k0: u64, k1: u64, capacity: uint) -> HashSet<T> { + HashSet { map: HashMap::with_capacity_and_keys(k0, k1, capacity) } + } + /// Reserve space for at least `n` elements in the hash table. pub fn reserve_at_least(&mut self, n: uint) { self.map.reserve_at_least(n) |
