-
Notifications
You must be signed in to change notification settings - Fork 301
Commit 9ee7cea
committed
Add HashMap variant with incremental resize
This patch adds a variant of HashMap, `IncrHashMap`, that supports
incremental resizing. It uses the same underlying hash table
implementation as `HashMap` (i.e., `RawTable`), but where the standard
implementation performs all-at-once resizing when the map must grow to
accommodate new elements, this implementation instead spreads the
resizing load across subsequent inserts.
To do this, it keeps both a new, resized map, and the old, pre-resize
map around after a resize. The new map starts out mostly empty, and read
operations search in both tables. New inserts go into the new map, but
they also move a few items from the old map to the new one. When the old
map is empty, it is dropped, and all operations hit only the new map.
This map implementation offers more stable insert performance than
`HashMap`, but it does so at a cost:
- Reads and removals of old or missing keys are slower for a while
after a resize.
- Inserts are slower than their `HashMap` counterparts for a while
after a resize.
- Memory is not reclaimed immediately after a resize, only after all
the keys have been moved.
- `IncrHashMap` is slightly larger than `HashMap`, to account for the
bookkeeping needed to manage two maps during and after a resize.1 parent efbd036 commit 9ee7ceaCopy full SHA for 9ee7cea
3 files changed
+2070
-1
lines changed
0 commit comments