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(...@@ -605,7 +605,10 @@ pub fn ArrayHashMapUnmanaged(
605605
606 const Self = @This();606 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
610 const RemovalType = enum {613 const RemovalType = enum {
611 swap,614 swap,
...@@ -2393,7 +2396,7 @@ test "shrink" {...@@ -2393,7 +2396,7 @@ test "shrink" {
2393 defer map.deinit();2396 defer map.deinit();
23942397
2395 // This test is more interesting if we insert enough entries to allocate the index header.2398 // 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;
2397 var i: i32 = 0;2400 var i: i32 = 0;
2398 while (i < num_entries) : (i += 1)2401 while (i < num_entries) : (i += 1)
2399 try testing.expect((try map.fetchPut(i, i * 10)) == null);2402 try testing.expect((try map.fetchPut(i, i * 10)) == null);
...@@ -2404,7 +2407,7 @@ test "shrink" {...@@ -2404,7 +2407,7 @@ test "shrink" {
2404 // Test `shrinkRetainingCapacity`.2407 // Test `shrinkRetainingCapacity`.
2405 map.shrinkRetainingCapacity(17);2408 map.shrinkRetainingCapacity(17);
2406 try testing.expect(map.count() == 17);2409 try testing.expect(map.count() == 17);
2407 try testing.expect(map.capacity() == 20);2410 try testing.expect(map.capacity() >= num_entries);
2408 i = 0;2411 i = 0;
2409 while (i < num_entries) : (i += 1) {2412 while (i < num_entries) : (i += 1) {
2410 const gop = try map.getOrPut(i);2413 const gop = try map.getOrPut(i);
...@@ -2453,7 +2456,7 @@ test "reIndex" {...@@ -2453,7 +2456,7 @@ test "reIndex" {
2453 defer map.deinit();2456 defer map.deinit();
24542457
2455 // Populate via the API.2458 // Populate via the API.
2456 const num_indexed_entries = 20;2459 const num_indexed_entries = 200;
2457 var i: i32 = 0;2460 var i: i32 = 0;
2458 while (i < num_indexed_entries) : (i += 1)2461 while (i < num_indexed_entries) : (i += 1)
2459 try testing.expect((try map.fetchPut(i, i * 10)) == null);2462 try testing.expect((try map.fetchPut(i, i * 10)) == null);