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
11 lines
681 B
Plaintext
11 lines
681 B
Plaintext
Forcing real treeification: 20 keys with hashCode()==1, loadFactor=1000f (size-resize disabled)
|
|
===============================================================================================
|
|
|
|
All keys hash to the same bucket (see CollidingKey javadoc for why a resize can't separate them).
|
|
|
|
after inserting key #1 : table.length=16 bucket[1] chain=1 kind=Node
|
|
after inserting key #9 : table.length=32 bucket[1] chain=9 kind=Node
|
|
after inserting key #10 : table.length=64 bucket[1] chain=10 kind=Node
|
|
after inserting key #11 : table.length=64 bucket[1] chain=11 kind=TreeNode
|
|
|
|
Final state: table.length=64, bucket[1] kind=TreeNode, first became a tree at insert #11 |