From 6093fa7c4e29bc41eccedc74b075394707fb4b1e Mon Sep 17 00:00:00 2001 From: Rekai Musuka Date: Tue, 11 Apr 2023 01:51:37 -0500 Subject: [PATCH] fix: actually add new element when resizing array-mapped table --- src/HashArrayMappedTrie.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/HashArrayMappedTrie.zig b/src/HashArrayMappedTrie.zig index 0177763..2dd96d6 100644 --- a/src/HashArrayMappedTrie.zig +++ b/src/HashArrayMappedTrie.zig @@ -98,12 +98,13 @@ pub fn insert(self: *HashArrayMappedTrie, comptime key: []const u8, value: void) // Empty const old_len = @popCount(table.map); const new_base = try self.allocator.alloc(Node, old_len + 1); + const new_map = table.map | mask; var i: u5 = 0; for (0..@typeInfo(u32).Int.bits) |shift| { const mask_loop = @as(u32, 1) << @intCast(u5, shift); - if (table.map & mask_loop != 0) { + if (new_map & mask_loop != 0) { defer i += 1; const idx = @popCount(table.map & (mask_loop - 1)); @@ -114,7 +115,7 @@ pub fn insert(self: *HashArrayMappedTrie, comptime key: []const u8, value: void) self.allocator.free(table.base[0..old_len]); table.base = new_base.ptr; - table.map |= mask; + table.map = new_map; return; // inserted an elemnt into the Trie } else {