ArrayHashMap: support all operations that ArrayList support #7391
Labels
enhancement
Solving this issue will likely involve adding new logic or components to the codebase.
proposal
This issue suggests modifications. If it also has the "accepted" label then it is planned.
standard library
This issue involves writing Zig code for the standard library.
Milestone
This proposal is to treat ArrayHashMap as a data structure that can act both as an ArrayList and as a HashMap.
Here are some improvements I want to see:
getOrPut
related functions should additionally return the entry index.remove
should be changed toswapRemove
, andorderedRemove
should be introduced. Both of these operations are present in ArrayList and match what will be happening to the Hash Map's inner ArrayList.entries
field which is anArrayList
. This causes all the methods which rely on the index data to become illegal to call, until you callreIndex()
which then makes everything work again.fromOwnedArrayList
which takes ownership of an ArrayList as the entries field and callsreIndex()
shrinkRetainingCapacity
which does the same thing as in ArrayList but maintains the hash map index.shrinkAndFree
which maps to ArrayList.shrink (and we should rename ArrayList.shrink to shrinkAndFree as well)pop
.This use case comes from updating the
Cache
APIfiles
field to be an ArrayHashMap instead of an ArrayList:zig/src/Cache.zig
Line 178 in f7d6006
The text was updated successfully, but these errors were encountered: