MCPcopy
hub / github.com/Jack-Lee-Hiter/AlgorithmsByPython / rebalance

Method rebalance

AVL.py:128–140  ·  view source on GitHub ↗
(self, node)

Source from the content-addressed store, hash-verified

126 newRoot.balanceFactor = newRoot.balanceFactor + 1 + max(rotRoot.balanceFactor, 0)
127
128 def rebalance(self, node):
129 if node.balanceFactor < 0:
130 if node.rightChild.balanceFactor > 0:
131 self.rotateRight(node.rightChild)
132 self.rotateLeft(node)
133 else:
134 self.rotateLeft(node)
135 elif node.balanceFactor > 0:
136 if node.leftChild.balanceFactor < 0:
137 self.rotateLeft(node.leftChild)
138 self.rotateRight(node)
139 else:
140 self.rotateRight(node)
141
142 def __setitem__(self, k, v):
143 self.put(k, v)

Callers 1

updateBalanceMethod · 0.95

Calls 2

rotateRightMethod · 0.95
rotateLeftMethod · 0.95

Tested by

no test coverage detected