MCPcopy Create free account
hub / github.com/chaimleib/intervaltree / rotate

Method rotate

intervaltree/node.py:136–159  ·  view source on GitHub ↗

Does rotating, if necessary, to balance this node, and returns the new top node.

(self)

Source from the content-addressed store, hash-verified

134 return 1 + max(left_depth, right_depth)
135
136 def rotate(self):
137 """
138 Does rotating, if necessary, to balance this node, and
139 returns the new top node.
140 """
141 self.refresh_balance()
142 if abs(self.balance) < 2:
143 return self
144 # balance > 0 is the heavy side
145 my_heavy = self.balance > 0
146 child_heavy = self[my_heavy].balance > 0
147 if my_heavy == child_heavy or self[my_heavy].balance == 0:
148 ## Heavy sides same
149 # self save
150 # save -> 1 self
151 # 1
152 #
153 ## Heavy side balanced
154 # self save save
155 # save -> 1 self -> 1 self.rot()
156 # 1 2 2
157 return self.srotate()
158 else:
159 return self.drotate()
160
161 def srotate(self):
162 """Single rotation. Assumes that balance is +-2."""

Callers 7

__init__Method · 0.95
init_from_sortedMethod · 0.95
srotateMethod · 0.95
addMethod · 0.95
pop_greatest_childMethod · 0.95
pruneMethod · 0.80

Calls 3

refresh_balanceMethod · 0.95
srotateMethod · 0.95
drotateMethod · 0.95

Tested by

no test coverage detected