MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / balance

Method balance

Ports/CLDC11/src/java/util/TreeMap.java:4720–4759  ·  view source on GitHub ↗
(Node<K, V> x)

Source from the content-addressed store, hash-verified

4718 }
4719
4720 void balance(Node<K, V> x) {
4721 Node<K, V> y;
4722 x.color = true;
4723 while (x != root && x.parent.color) {
4724 if (x.parent == x.parent.parent.left) {
4725 y = x.parent.parent.right;
4726 if (y != null && y.color) {
4727 x.parent.color = false;
4728 y.color = false;
4729 x.parent.parent.color = true;
4730 x = x.parent.parent;
4731 } else {
4732 if (x == x.parent.right) {
4733 x = x.parent;
4734 leftRotate(x);
4735 }
4736 x.parent.color = false;
4737 x.parent.parent.color = true;
4738 rightRotate(x.parent.parent);
4739 }
4740 } else {
4741 y = x.parent.parent.left;
4742 if (y != null && y.color) {
4743 x.parent.color = false;
4744 y.color = false;
4745 x.parent.parent.color = true;
4746 x = x.parent.parent;
4747 } else {
4748 if (x == x.parent.left) {
4749 x = x.parent;
4750 rightRotate(x);
4751 }
4752 x.parent.color = false;
4753 x.parent.parent.color = true;
4754 leftRotate(x.parent.parent);
4755 }
4756 }
4757 }
4758 root.color = false;
4759 }
4760
4761 private void rightRotate(Node<K, V> x) {
4762 Node<K, V> y = x.left;

Callers 2

addToLastMethod · 0.95
putImplMethod · 0.95

Calls 2

leftRotateMethod · 0.95
rightRotateMethod · 0.95

Tested by

no test coverage detected