## DEBUG ONLY ## Recursively ensures that the invariants of an interval subtree hold.
(self, parents=set())
| 461 | return result |
| 462 | |
| 463 | def verify(self, parents=set()): |
| 464 | """ |
| 465 | ## DEBUG ONLY ## |
| 466 | Recursively ensures that the invariants of an interval subtree |
| 467 | hold. |
| 468 | """ |
| 469 | assert(isinstance(self.s_center, set)) |
| 470 | |
| 471 | bal = self.balance |
| 472 | assert abs(bal) < 2, \ |
| 473 | "Error: Rotation should have happened, but didn't! \n{}".format( |
| 474 | self.print_structure(tostring=True) |
| 475 | ) |
| 476 | self.refresh_balance() |
| 477 | assert bal == self.balance, \ |
| 478 | "Error: self.balance not set correctly! \n{}".format( |
| 479 | self.print_structure(tostring=True) |
| 480 | ) |
| 481 | |
| 482 | assert self.s_center, \ |
| 483 | "Error: s_center is empty! \n{}".format( |
| 484 | self.print_structure(tostring=True) |
| 485 | ) |
| 486 | for iv in self.s_center: |
| 487 | assert hasattr(iv, 'begin') |
| 488 | assert hasattr(iv, 'end') |
| 489 | assert iv.begin < iv.end |
| 490 | assert iv.overlaps(self.x_center) |
| 491 | for parent in sorted(parents): |
| 492 | assert not iv.contains_point(parent), \ |
| 493 | "Error: Overlaps ancestor ({})! \n{}\n\n{}".format( |
| 494 | parent, iv, self.print_structure(tostring=True) |
| 495 | ) |
| 496 | if self[0]: |
| 497 | assert self[0].x_center < self.x_center, \ |
| 498 | "Error: Out-of-order left child! {}".format(self.x_center) |
| 499 | self[0].verify(parents.union([self.x_center])) |
| 500 | if self[1]: |
| 501 | assert self[1].x_center > self.x_center, \ |
| 502 | "Error: Out-of-order right child! {}".format(self.x_center) |
| 503 | self[1].verify(parents.union([self.x_center])) |
| 504 | |
| 505 | def __getitem__(self, index): |
| 506 | """ |