Skip to content

Commit b0e13e0

Browse files
committed
Add HashSet::with_capacity_and_keys() function
This function can be use to create HashSets before the tls is initialized.
1 parent 67ed30c commit b0e13e0

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/libstd/hashmap.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -687,6 +687,17 @@ impl<T:Hash + Eq> HashSet<T> {
687687
HashSet { map: HashMap::with_capacity(capacity) }
688688
}
689689

690+
/// Create an empty HashSet with space for at least `capacity`
691+
/// elements in the hash table, using `k0` and `k1` as the keys.
692+
///
693+
/// Warning: `k0` and `k1` are normally randomly generated, and
694+
/// are designed to allow HashSets to be resistant to attacks that
695+
/// cause many collisions and very poor performance. Setting them
696+
/// manually using this function can expose a DoS attack vector.
697+
pub fn with_capacity_and_keys(k0: u64, k1: u64, capacity: uint) -> HashSet<T> {
698+
HashSet { map: HashMap::with_capacity_and_keys(k0, k1, capacity) }
699+
}
700+
690701
/// Reserve space for at least `n` elements in the hash table.
691702
pub fn reserve_at_least(&mut self, n: uint) {
692703
self.map.reserve_at_least(n)

0 commit comments

Comments
 (0)