MCPcopy
hub / github.com/google/mangle / rebalance

Method rebalance

factstore/interval_tree.go:311–338  ·  view source on GitHub ↗

rebalance rebalances a node after insertion.

(node *treeNode)

Source from the content-addressed store, hash-verified

309
310// rebalance rebalances a node after insertion.
311func (t *IntervalTree) rebalance(node *treeNode) *treeNode {
312 updateHeight(node)
313 updateMaxEnd(node)
314
315 balance := balanceFactor(node)
316
317 // Left-heavy
318 if balance > 1 {
319 if balanceFactor(node.left) < 0 {
320 // Left-Right case
321 node.left = t.rotateLeft(node.left)
322 }
323 // Left-Left case
324 return t.rotateRight(node)
325 }
326
327 // Right-heavy
328 if balance < -1 {
329 if balanceFactor(node.right) > 0 {
330 // Right-Left case
331 node.right = t.rotateRight(node.right)
332 }
333 // Right-Right case
334 return t.rotateLeft(node)
335 }
336
337 return node
338}
339
340// max returns the maximum of two int64 values.
341func maxInt(a, b int64) int64 {

Callers 1

insertMethod · 0.95

Calls 5

rotateLeftMethod · 0.95
rotateRightMethod · 0.95
updateHeightFunction · 0.85
updateMaxEndFunction · 0.85
balanceFactorFunction · 0.85

Tested by

no test coverage detected