Skip to content

Commit 53216d2

Browse files
committed
std.ArrayHashMap: base linear_scan_max on cache line size
1 parent 58f9288 commit 53216d2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

lib/std/array_hash_map.zig

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,10 @@ pub fn ArrayHashMapUnmanaged(
605605

606606
const Self = @This();
607607

608-
const linear_scan_max = 8;
608+
const linear_scan_max = @as(comptime_int, @max(1, @as(comptime_int, @min(
609+
std.atomic.cache_line / @as(comptime_int, @max(1, @sizeOf(Hash))),
610+
std.atomic.cache_line / @as(comptime_int, @max(1, @sizeOf(K))),
611+
))));
609612

610613
const RemovalType = enum {
611614
swap,
@@ -2393,7 +2396,7 @@ test "shrink" {
23932396
defer map.deinit();
23942397

23952398
// This test is more interesting if we insert enough entries to allocate the index header.
2396-
const num_entries = 20;
2399+
const num_entries = 200;
23972400
var i: i32 = 0;
23982401
while (i < num_entries) : (i += 1)
23992402
try testing.expect((try map.fetchPut(i, i * 10)) == null);
@@ -2404,7 +2407,7 @@ test "shrink" {
24042407
// Test `shrinkRetainingCapacity`.
24052408
map.shrinkRetainingCapacity(17);
24062409
try testing.expect(map.count() == 17);
2407-
try testing.expect(map.capacity() == 20);
2410+
try testing.expect(map.capacity() >= num_entries);
24082411
i = 0;
24092412
while (i < num_entries) : (i += 1) {
24102413
const gop = try map.getOrPut(i);
@@ -2453,7 +2456,7 @@ test "reIndex" {
24532456
defer map.deinit();
24542457

24552458
// Populate via the API.
2456-
const num_indexed_entries = 20;
2459+
const num_indexed_entries = 200;
24572460
var i: i32 = 0;
24582461
while (i < num_indexed_entries) : (i += 1)
24592462
try testing.expect((try map.fetchPut(i, i * 10)) == null);

0 commit comments

Comments
 (0)