## FOR DEBUGGING ONLY ## Checks the table to ensure that the invariants are held.
(self)
| 994 | return result |
| 995 | |
| 996 | def verify(self): |
| 997 | """ |
| 998 | ## FOR DEBUGGING ONLY ## |
| 999 | Checks the table to ensure that the invariants are held. |
| 1000 | """ |
| 1001 | if self.all_intervals: |
| 1002 | ## top_node.all_children() == self.all_intervals |
| 1003 | try: |
| 1004 | assert self.top_node.all_children() == self.all_intervals |
| 1005 | except AssertionError as e: |
| 1006 | print( |
| 1007 | 'Error: the tree and the membership set are out of sync!' |
| 1008 | ) |
| 1009 | tivs = set(self.top_node.all_children()) |
| 1010 | print('top_node.all_children() - all_intervals:') |
| 1011 | try: |
| 1012 | pprint |
| 1013 | except NameError: |
| 1014 | from pprint import pprint |
| 1015 | pprint(tivs - self.all_intervals) |
| 1016 | print('all_intervals - top_node.all_children():') |
| 1017 | pprint(self.all_intervals - tivs) |
| 1018 | raise e |
| 1019 | |
| 1020 | ## All members are Intervals |
| 1021 | for iv in self: |
| 1022 | assert isinstance(iv, Interval), ( |
| 1023 | "Error: Only Interval objects allowed in IntervalTree:" |
| 1024 | " {0}".format(iv) |
| 1025 | ) |
| 1026 | |
| 1027 | ## No null intervals |
| 1028 | for iv in self: |
| 1029 | assert not iv.is_null(), ( |
| 1030 | "Error: Null Interval objects not allowed in IntervalTree:" |
| 1031 | " {0}".format(iv) |
| 1032 | ) |
| 1033 | |
| 1034 | ## Reconstruct boundary_table |
| 1035 | bound_check = {} |
| 1036 | for iv in self: |
| 1037 | if iv.begin in bound_check: |
| 1038 | bound_check[iv.begin] += 1 |
| 1039 | else: |
| 1040 | bound_check[iv.begin] = 1 |
| 1041 | if iv.end in bound_check: |
| 1042 | bound_check[iv.end] += 1 |
| 1043 | else: |
| 1044 | bound_check[iv.end] = 1 |
| 1045 | |
| 1046 | ## Reconstructed boundary table (bound_check) ==? boundary_table |
| 1047 | assert set(self.boundary_table.keys()) == set(bound_check.keys()),\ |
| 1048 | 'Error: boundary_table is out of sync with ' \ |
| 1049 | 'the intervals in the tree!' |
| 1050 | |
| 1051 | # For efficiency reasons this should be iteritems in Py2, but we |
| 1052 | # don't care much for efficiency in debug methods anyway. |
| 1053 | for key, val in self.boundary_table.items(): |