1
Fork 0

Changed interners to start with preallocated capacity

This commit is contained in:
Michał Kostrubiec 2025-02-25 00:43:25 +01:00
parent 28b83ee596
commit 7d2cfcab9d
2 changed files with 33 additions and 24 deletions

View file

@ -143,6 +143,9 @@ pub fn shards() -> usize {
pub type ShardedHashMap<K, V> = Sharded<FxHashMap<K, V>>;
impl<K: Eq, V> ShardedHashMap<K, V> {
pub fn with_capacity(cap: usize) -> Self {
Self::new(|| FxHashMap::with_capacity_and_hasher(cap, rustc_hash::FxBuildHasher::default()))
}
pub fn len(&self) -> usize {
self.lock_shards().map(|shard| shard.len()).sum()
}