diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2018-04-11 00:33:14 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2018-04-11 00:33:14 -0400 |
| commit | f43711e5fbbedafa1c28c933fdca0949427c77cd (patch) | |
| tree | 5d7aa554aab5a6b9a012dcdb1562851ba1fdb81e /std/hash_map.zig | |
| parent | 2ec1cec92d018d25f720c43a7586a12eafd2cbeb (diff) | |
| parent | 58c6424d4fe64f88e25714d20d5755d31a7775c1 (diff) | |
| download | zig-f43711e5fbbedafa1c28c933fdca0949427c77cd.tar.gz zig-f43711e5fbbedafa1c28c933fdca0949427c77cd.zip | |
Merge branch 'bnoordhuis-fix879'
Diffstat (limited to 'std/hash_map.zig')
| -rw-r--r-- | std/hash_map.zig | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/std/hash_map.zig b/std/hash_map.zig index becced64ff..29dd233753 100644 --- a/std/hash_map.zig +++ b/std/hash_map.zig @@ -114,6 +114,7 @@ pub fn HashMap(comptime K: type, comptime V: type, } pub fn remove(hm: &Self, key: K) ?&Entry { + if (hm.entries.len == 0) return null; hm.incrementModificationCount(); const start_index = hm.keyToIndex(key); {var roll_over: usize = 0; while (roll_over <= hm.max_distance_from_start_index) : (roll_over += 1) { @@ -236,7 +237,10 @@ pub fn HashMap(comptime K: type, comptime V: type, } test "basic hash map usage" { - var map = HashMap(i32, i32, hash_i32, eql_i32).init(debug.global_allocator); + var direct_allocator = std.heap.DirectAllocator.init(); + defer direct_allocator.deinit(); + + var map = HashMap(i32, i32, hash_i32, eql_i32).init(&direct_allocator.allocator); defer map.deinit(); assert((map.put(1, 11) catch unreachable) == null); |
