aboutsummaryrefslogtreecommitdiff
path: root/lib/std/json.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-07-03 23:57:24 +0000
committerAndrew Kelley <andrew@ziglang.org>2020-07-05 21:11:42 +0000
commitb3b6ccba50ef7a683ad05546cba2b71e7d10489f (patch)
treed49e5c0de641a60c3b8276a8e2afab014acf0289 /lib/std/json.zig
parent70dca0a0c6fd27bc39ac3a37edd2a6908bc0198f (diff)
downloadzig-b3b6ccba50ef7a683ad05546cba2b71e7d10489f.tar.gz
zig-b3b6ccba50ef7a683ad05546cba2b71e7d10489f.zip
reimplement std.HashMap
* breaking changes to the API. Some of the weird decisions from before are changed to what would be more expected. - `get` returns `?V`, use `getEntry` for the old API. - `put` returns `!void`, use `fetchPut` for the old API. * HashMap now has a comptime parameter of whether to store hashes with entries. AutoHashMap has heuristics on whether to set this parameter. For example, for integers, it is false, since equality checking is cheap, but for strings, it is true, since equality checking is probably expensive. * The implementation has a separate array for entry_index / distance_from_start_index. Entries no longer has holes; it is an ArrayList, and iteration is simpler and more cache coherent. This is inspired by Python's new dictionaries. * HashMap is separated into an "unmanaged" and a "managed" API. The unmanaged API is where the actual implementation is; the managed API wraps it and provides a more convenient API, storing the allocator. * Memory usage: When there are less than or equal to 8 entries, HashMap now incurs only a single pointer-size integer as overhead, opposed to using an ArrayList. * Since the entries array is separate from the indexes array, the holes in the indexes array take up less room than the holes in the entries array otherwise would. However the entries array also allocates additional capacity for appending into the array. * HashMap now maintains insertion order. Deletion performs a "swap remove". It's now possible to modify the HashMap while iterating.
Diffstat (limited to 'lib/std/json.zig')
0 files changed, 0 insertions, 0 deletions