(Node<K, V> x)
| 4696 | } |
| 4697 | |
| 4698 | void balance(Node<K, V> x) { |
| 4699 | Node<K, V> y; |
| 4700 | x.color = true; |
| 4701 | while (x != root && x.parent.color) { |
| 4702 | if (x.parent == x.parent.parent.left) { |
| 4703 | y = x.parent.parent.right; |
| 4704 | if (y != null && y.color) { |
| 4705 | x.parent.color = false; |
| 4706 | y.color = false; |
| 4707 | x.parent.parent.color = true; |
| 4708 | x = x.parent.parent; |
| 4709 | } else { |
| 4710 | if (x == x.parent.right) { |
| 4711 | x = x.parent; |
| 4712 | leftRotate(x); |
| 4713 | } |
| 4714 | x.parent.color = false; |
| 4715 | x.parent.parent.color = true; |
| 4716 | rightRotate(x.parent.parent); |
| 4717 | } |
| 4718 | } else { |
| 4719 | y = x.parent.parent.left; |
| 4720 | if (y != null && y.color) { |
| 4721 | x.parent.color = false; |
| 4722 | y.color = false; |
| 4723 | x.parent.parent.color = true; |
| 4724 | x = x.parent.parent; |
| 4725 | } else { |
| 4726 | if (x == x.parent.left) { |
| 4727 | x = x.parent; |
| 4728 | rightRotate(x); |
| 4729 | } |
| 4730 | x.parent.color = false; |
| 4731 | x.parent.parent.color = true; |
| 4732 | leftRotate(x.parent.parent); |
| 4733 | } |
| 4734 | } |
| 4735 | } |
| 4736 | root.color = false; |
| 4737 | } |
| 4738 | |
| 4739 | private void rightRotate(Node<K, V> x) { |
| 4740 | Node<K, V> y = x.left; |
no test coverage detected