Hash Array Mapped Trie (HAMT)

Hash → 5-bit chunks → bitmap + popcount → dense child array → immutable insert (path copying)

get: O(log₃₂ n) insert: O(log₃₂ n) delete: O(log₃₂ n) space: O(n)

Controls

slow fast
path / current chunk copied / new shared leaf / set slot

1 · Hash of key, sliced into 5-bit chunks

2 · Bitmap + popcount at the current node

Slots 0..31 — purple = present. Target slot outlined; green underline = slots counted by popcount (below target).

3 · Trie (insert copies only the path; rest is shared)

Info

Press Insert with a key, then Step ▶ to walk the algorithm one stage at a time.

Big-O

OperationTimeExtra space / updateNote
get(key)O(log₃₂ n)O(1)~6 hops for 10⁹ keys
insert(key,val)O(log₃₂ n)O(log₃₂ n)copies path, shares rest
delete(key)O(log₃₂ n)O(log₃₂ n)collapses single-child nodes
popcount indexO(1)O(1)one hardware instruction
whole-map memoryO(n)bitmap+popcount, no 32-wide waste

Operation Log