Concurrent Hash Map

Per-bucket locking + CAS (Java 8 style). Threads inserting into different buckets run in parallel; threads hitting the same bucket serialize. Watch a lock-free CAS install into an empty bucket, a synchronized-on-head insert into a populated one, and a cooperative concurrent resize that transfers buckets behind ForwardingNode markers.

get: lock-free O(1) put: CAS or sync-head resize: cooperative tree-bin > 8 → O(log n)
Idle bucket
CAS in progress (lock-free)
Lock held (sync on head)
Freshly inserted node
ForwardingNode (resizing)
Buckets
8
Entries
0
Load factor
0.00
CAS ops
0
Locks taken
0
State
idle

table (old / current)

nextTable (resize target, 2× size)

Trace

Press Auto demo, or type a key and put. Empty bucket → lock-free CAS. Occupied bucket → synchronized on the first node. At load factor > 0.75 the map resizes by cooperatively transferring buckets to a 2× table.

Complexity

OperationAvgWorst (chain)Worst (tree-bin)Sync cost
get(k)O(1)O(n)O(log n)lock-free
put(k) — empty bucketO(1)O(1)O(1)1 CAS
put(k) — populatedO(1)O(n)O(log n)sync(head)
remove(k)O(1)O(n)O(log n)sync(head)
resizeO(n) totalO(n)O(n)cooperative
size()O(cells)O(cells)O(cells)striped, approx

Operation Log