Skip to content

Commit 4e1a038

Browse files
committed
fix initial capacity (and typo)
1 parent 7195a44 commit 4e1a038

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

crates/hash-sorted-map/src/group_ops.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@ pub const GROUP_SIZE: usize = 16;
44
#[cfg(not(target_arch = "x86_64"))]
55
pub const GROUP_SIZE: usize = 8;
66

7+
/// Maximum safe fill ratio (keys / primary slots) that keeps overflow within
8+
/// the 12.5% reserve budget at p95 confidence. Derived from simulation.
9+
#[cfg(target_arch = "x86_64")]
10+
pub const MAX_FILL: f64 = 0.71;
11+
#[cfg(not(target_arch = "x86_64"))]
12+
pub const MAX_FILL: f64 = 0.67;
13+
714
pub const CTRL_EMPTY: u8 = 0x00;
815

916
#[cfg(target_arch = "x86_64")]

crates/hash-sorted-map/src/hash_sorted_map.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ impl<K, V, S> HashSortedMap<K, V, S> {
6565
}
6666

6767
pub fn with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Self {
68-
let adjusted = capacity.checked_mul(8).unwrap_or(usize::MAX) / 7;
69-
let min_groups = (adjusted / GROUP_SIZE).max(1).next_power_of_two();
68+
let adjusted = (capacity as f64 / group_ops::MAX_FILL).ceil() as usize;
69+
let min_groups = (adjusted.div_ceil(GROUP_SIZE)).max(1).next_power_of_two();
7070
let n_bits = min_groups.trailing_zeros().max(1);
7171
let (groups, num_primary) = Self::alloc_groups(n_bits);
7272
Self {

crates/hash-sorted-map/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
mod group_ops;
22
mod hash_sorted_map;
33

4-
pub use hash_sorted_map::{Entry, HashSortedMap, OccupiedEntry, VacandEntry};
4+
pub use hash_sorted_map::{Entry, HashSortedMap, OccupiedEntry, VacantEntry};

0 commit comments

Comments
 (0)