HashMap红黑树

上篇文章说到,如果链表的长度>=7的时候,链表会转成红黑树,本文就来详细的分析一下红黑树的旋转过程。

首先来看一段代码

HashMap红黑树

本文的提到的红黑树的转换主要是在hd.treeify(tab);这个方法里

详细代码如下,下面来分析一下具体的过程

final void treeify(Node[] tab) {

TreeNode root = null;

for (TreeNode x = this, next; x != null; x = next) {

next = (TreeNode)x.next;

x.left = x.right = null;

if (root == null) {

x.parent = null;

x.red = false;

root = x;

推荐阅读