Skip to content

Commit 8c38d5b

Browse files
committed
std.ArrayHashMap: base linear_scan_max on cache line size
1 parent 4162f40 commit 8c38d5b

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

lib/std/array_hash_map.zig

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,11 @@ 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+
std.atomic.cache_line / @as(comptime_int, @max(1, @sizeOf(V))),
612+
))));
609613

610614
const RemovalType = enum {
611615
swap,
@@ -2376,7 +2380,7 @@ test "shrink" {
23762380
defer map.deinit();
23772381

23782382
// This test is more interesting if we insert enough entries to allocate the index header.
2379-
const num_entries = 20;
2383+
const num_entries = 200;
23802384
var i: i32 = 0;
23812385
while (i < num_entries) : (i += 1)
23822386
try testing.expect((try map.fetchPut(i, i * 10)) == null);
@@ -2387,7 +2391,7 @@ test "shrink" {
23872391
// Test `shrinkRetainingCapacity`.
23882392
map.shrinkRetainingCapacity(17);
23892393
try testing.expect(map.count() == 17);
2390-
try testing.expect(map.capacity() == 20);
2394+
try testing.expect(map.capacity() >= num_entries);
23912395
i = 0;
23922396
while (i < num_entries) : (i += 1) {
23932397
const gop = try map.getOrPut(i);
@@ -2436,7 +2440,7 @@ test "reIndex" {
24362440
defer map.deinit();
24372441

24382442
// Populate via the API.
2439-
const num_indexed_entries = 20;
2443+
const num_indexed_entries = 200;
24402444
var i: i32 = 0;
24412445
while (i < num_indexed_entries) : (i += 1)
24422446
try testing.expect((try map.fetchPut(i, i * 10)) == null);

0 commit comments

Comments
 (0)