authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-11 11:37:12-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-02-12 01:55:26-08:00
log53216d2f22053ca94a68f5da234038c01f73d60f
tree9b9d2b5a6a82c7848da9886b2ac75900b4e12998
parent58f928814d026fbf8fe7fef778a9fc890f9283bb

std.ArrayHashMap: base linear_scan_max on cache line size


1 files changed, 7 insertions(+), 4 deletions(-)

lib/std/array_hash_map.zig+7-4
......@@ -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);