mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
std.ArrayHashMap: base linear_scan_max on cache line size
This commit is contained in:
parent
58f928814d
commit
53216d2f22
@ -605,7 +605,10 @@ pub fn ArrayHashMapUnmanaged(
|
|||||||
|
|
||||||
const Self = @This();
|
const Self = @This();
|
||||||
|
|
||||||
const linear_scan_max = 8;
|
const linear_scan_max = @as(comptime_int, @max(1, @as(comptime_int, @min(
|
||||||
|
std.atomic.cache_line / @as(comptime_int, @max(1, @sizeOf(Hash))),
|
||||||
|
std.atomic.cache_line / @as(comptime_int, @max(1, @sizeOf(K))),
|
||||||
|
))));
|
||||||
|
|
||||||
const RemovalType = enum {
|
const RemovalType = enum {
|
||||||
swap,
|
swap,
|
||||||
@ -2393,7 +2396,7 @@ test "shrink" {
|
|||||||
defer map.deinit();
|
defer map.deinit();
|
||||||
|
|
||||||
// This test is more interesting if we insert enough entries to allocate the index header.
|
// This test is more interesting if we insert enough entries to allocate the index header.
|
||||||
const num_entries = 20;
|
const num_entries = 200;
|
||||||
var i: i32 = 0;
|
var i: i32 = 0;
|
||||||
while (i < num_entries) : (i += 1)
|
while (i < num_entries) : (i += 1)
|
||||||
try testing.expect((try map.fetchPut(i, i * 10)) == null);
|
try testing.expect((try map.fetchPut(i, i * 10)) == null);
|
||||||
@ -2404,7 +2407,7 @@ test "shrink" {
|
|||||||
// Test `shrinkRetainingCapacity`.
|
// Test `shrinkRetainingCapacity`.
|
||||||
map.shrinkRetainingCapacity(17);
|
map.shrinkRetainingCapacity(17);
|
||||||
try testing.expect(map.count() == 17);
|
try testing.expect(map.count() == 17);
|
||||||
try testing.expect(map.capacity() == 20);
|
try testing.expect(map.capacity() >= num_entries);
|
||||||
i = 0;
|
i = 0;
|
||||||
while (i < num_entries) : (i += 1) {
|
while (i < num_entries) : (i += 1) {
|
||||||
const gop = try map.getOrPut(i);
|
const gop = try map.getOrPut(i);
|
||||||
@ -2453,7 +2456,7 @@ test "reIndex" {
|
|||||||
defer map.deinit();
|
defer map.deinit();
|
||||||
|
|
||||||
// Populate via the API.
|
// Populate via the API.
|
||||||
const num_indexed_entries = 20;
|
const num_indexed_entries = 200;
|
||||||
var i: i32 = 0;
|
var i: i32 = 0;
|
||||||
while (i < num_indexed_entries) : (i += 1)
|
while (i < num_indexed_entries) : (i += 1)
|
||||||
try testing.expect((try map.fetchPut(i, i * 10)) == null);
|
try testing.expect((try map.fetchPut(i, i * 10)) == null);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user