(Node<K, V> x)
| 1726 | } |
| 1727 | |
| 1728 | void balance(Node<K, V> x) { |
| 1729 | Node<K, V> y; |
| 1730 | x.color = true; |
| 1731 | while (x != root && x.parent.color) { |
| 1732 | if (x.parent == x.parent.parent.left) { |
| 1733 | y = x.parent.parent.right; |
| 1734 | if (y != null && y.color) { |
| 1735 | x.parent.color = false; |
| 1736 | y.color = false; |
| 1737 | x.parent.parent.color = true; |
| 1738 | x = x.parent.parent; |
| 1739 | } else { |
| 1740 | if (x == x.parent.right) { |
| 1741 | x = x.parent; |
| 1742 | leftRotate(x); |
| 1743 | } |
| 1744 | x.parent.color = false; |
| 1745 | x.parent.parent.color = true; |
| 1746 | rightRotate(x.parent.parent); |
| 1747 | } |
| 1748 | } else { |
| 1749 | y = x.parent.parent.left; |
| 1750 | if (y != null && y.color) { |
| 1751 | x.parent.color = false; |
| 1752 | y.color = false; |
| 1753 | x.parent.parent.color = true; |
| 1754 | x = x.parent.parent; |
| 1755 | } else { |
| 1756 | if (x == x.parent.left) { |
| 1757 | x = x.parent; |
| 1758 | rightRotate(x); |
| 1759 | } |
| 1760 | x.parent.color = false; |
| 1761 | x.parent.parent.color = true; |
| 1762 | leftRotate(x.parent.parent); |
| 1763 | } |
| 1764 | } |
| 1765 | } |
| 1766 | root.color = false; |
| 1767 | } |
| 1768 | |
| 1769 | private void rightRotate(Node<K, V> x) { |
| 1770 | Node<K, V> y = x.left; |
no test coverage detected