Skip to content

Commit 68241c6

Browse files
committed
std.ArrayHashMap: base linear_scan_max on cache line size
1 parent 33f0d45 commit 68241c6

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,
@@ -2376,7 +2379,7 @@ test "shrink" {
23762379
defer map.deinit();
23772380

23782381
// This test is more interesting if we insert enough entries to allocate the index header.
2379-
const num_entries = 20;
2382+
const num_entries = 200;
23802383
var i: i32 = 0;
23812384
while (i < num_entries) : (i += 1)
23822385
try testing.expect((try map.fetchPut(i, i * 10)) == null);
@@ -2387,7 +2390,7 @@ test "shrink" {
23872390
// Test `shrinkRetainingCapacity`.
23882391
map.shrinkRetainingCapacity(17);
23892392
try testing.expect(map.count() == 17);
2390-
try testing.expect(map.capacity() == 20);
2393+
try testing.expect(map.capacity() >= num_entries);
23912394
i = 0;
23922395
while (i < num_entries) : (i += 1) {
23932396
const gop = try map.getOrPut(i);
@@ -2436,7 +2439,7 @@ test "reIndex" {
24362439
defer map.deinit();
24372440

24382441
// Populate via the API.
2439-
const num_indexed_entries = 20;
2442+
const num_indexed_entries = 200;
24402443
var i: i32 = 0;
24412444
while (i < num_indexed_entries) : (i += 1)
24422445
try testing.expect((try map.fetchPut(i, i * 10)) == null);

0 commit comments

Comments
 (0)