On a subtree where the root node's s_center is empty, return a new subtree with no empty s_centers.
(self)
| 320 | return result |
| 321 | |
| 322 | def prune(self): |
| 323 | """ |
| 324 | On a subtree where the root node's s_center is empty, |
| 325 | return a new subtree with no empty s_centers. |
| 326 | """ |
| 327 | if not self[0] or not self[1]: # if I have an empty branch |
| 328 | direction = not self[0] # graft the other branch here |
| 329 | #if trace: |
| 330 | # print('Grafting {} branch'.format( |
| 331 | # 'right' if direction else 'left')) |
| 332 | |
| 333 | result = self[direction] |
| 334 | #if result: result.verify() |
| 335 | return result |
| 336 | else: |
| 337 | # Replace the root node with the greatest predecessor. |
| 338 | heir, self[0] = self[0].pop_greatest_child() |
| 339 | #if trace: |
| 340 | # print('Replacing {} with {}.'.format( |
| 341 | # self.x_center, heir.x_center |
| 342 | # )) |
| 343 | # print('Removed greatest predecessor:') |
| 344 | # self.print_structure() |
| 345 | |
| 346 | #if self[0]: self[0].verify() |
| 347 | #if self[1]: self[1].verify() |
| 348 | |
| 349 | # Set up the heir as the new root node |
| 350 | (heir[0], heir[1]) = (self[0], self[1]) |
| 351 | #if trace: print('Setting up the heir:') |
| 352 | #if trace: heir.print_structure() |
| 353 | |
| 354 | # popping the predecessor may have unbalanced this node; |
| 355 | # fix it |
| 356 | heir.refresh_balance() |
| 357 | heir = heir.rotate() |
| 358 | #heir.verify() |
| 359 | #if trace: print('Rotated the heir:') |
| 360 | #if trace: heir.print_structure() |
| 361 | return heir |
| 362 | |
| 363 | def pop_greatest_child(self): |
| 364 | """ |
no test coverage detected