Companion code for the ankurm.com post "Top 40 Java Collections Interview Questions (HashMap Internals to Fail-Fast Iterators)". Verified against JDK 25's own HashMap source (TREEIFY_THRESHOLD=8, UNTREEIFY_THRESHOLD=6, MIN_TREEIFY_CAPACITY=64), with every claim backed by a committed docs/output/*.txt transcript from a real run. Co-Authored-By: Claude Sonnet 5 <[email protected]> Claude-Session: https://claude.ai/code/session_01YXCrLgRKFgCh9RHKW8xaqJ
17 lines
868 B
Plaintext
17 lines
868 B
Plaintext
Real bucket layout of a 6-entry HashMap<String,Integer> (default capacity)
|
|
==========================================================================
|
|
|
|
map.size() = 6
|
|
table.length = 16 | non-empty buckets = 4
|
|
bucket[ 0] chain=2 kind=Node
|
|
bucket[ 1] chain=2 kind=Node
|
|
bucket[ 4] chain=1 kind=Node
|
|
bucket[ 5] chain=1 kind=Node
|
|
|
|
Index for each key, computed the same way HashMap.hash() does it:
|
|
apple hashCode=93029210 spread=93030097 index=(16-1)&spread=1
|
|
banana hashCode=-1396355227 spread=-1396317280 index=(16-1)&spread=0
|
|
cherry hashCode=-1361513063 spread=-1361552575 index=(16-1)&spread=1
|
|
date hashCode=3076014 spread=3075968 index=(16-1)&spread=0
|
|
egg hashCode=100357 spread=100356 index=(16-1)&spread=4
|
|
fig hashCode=101380 spread=101381 index=(16-1)&spread=5 |