-
Notifications
You must be signed in to change notification settings - Fork 45.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HashMap(JDK1.8)源码+底层数据结构分析.md中put方法的流程图,转变红黑树时的疑问 #1087
Comments
Thank you. |
感觉作者改的,跟问题反馈的没啥关系,树化是在插入链表后,只有插入链表末尾时,才会触发树化判断,即:如果当前链表长度大于等于8,执行树化【treeifyBin(tab, hash)】,执行树化时会判断当前table的长度,如果长度<64,进行resize而不是树化;图中,转为红黑树后,并不是红黑树插入,是已经插入链表后,才进行的红黑树转换 |
该图多处细节跟源码出入较大,建议作者重新绘制,向Map中put是,如果是替换,size是不会++的,只有插入新的key,才会执行++ |
补充一下,扩容时此时binCount为7(即p指向第8个节点,p.next == null),再将新节点插入至链表末尾(注,此时该链表已有9个节点),随后触发(binCount >= TREEIFY_THRESHOLD - 1)再执行treeifyBin(tab, hash)。 |
这里应该是先链表尾插,然后treeifyBin(tab, hash);跳出循环,执行最后面的++modCount;和判断是否需要扩容了吧?
The text was updated successfully, but these errors were encountered: