From 904fa4d94f30825bec490133ff402c6350f45e26 Mon Sep 17 00:00:00 2001 From: Sam Atman Date: Wed, 4 Feb 2026 21:21:14 -0500 Subject: Teasing out canonicalization After coping with a spuriously broken autohash for awhile, I got the one remaining hash table moved into memory, so there's no further reason to put up with allocation of basic structures. So that's nice. --- src/comptime_map.zig | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/comptime_map.zig') diff --git a/src/comptime_map.zig b/src/comptime_map.zig index b2c4d11..d41f6f8 100644 --- a/src/comptime_map.zig +++ b/src/comptime_map.zig @@ -28,7 +28,7 @@ pub fn ComptimeHashMap(comptime K: type, comptime V: type, comptime ctx: type, c }; // ensure that the hash map will be at most 60% full - const size = if (@import("builtin").is_test) values.len else math.ceilPowerOfTwo(usize, values.len * 5 / 3) catch unreachable; + const size = math.ceilPowerOfTwo(usize, values.len * 5 / 3) catch unreachable; comptime var slots = [1]Entry{.{}} ** size; comptime var distance: [size]usize = .{0} ** size; @@ -148,6 +148,15 @@ test "auto comptime hash map" { try testing.expect(map.get(4_000_000) == null); } +test "array pair comptime hash map" { + const map = AutoComptimeHashMap([2]u32, u21, .{ + .{ .{ 2, 3 }, 5 }, + .{ .{ 42, 56 }, 12 }, + .{ .{ 2, 4 }, 6 }, + }); + try testing.expect(map.has(.{ 2, 4 })); +} + const std = @import("std"); const hash_map = std.hash_map; const testing = std.testing; @@ -174,3 +183,4 @@ const math = std.math; // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. + -- cgit v1.2.3