Returns the largest element in this tree which is at most label. This method is guaranteed to run in O(log(n)) time.
(self, label: int)
| 365 | return self.left.search(label) |
| 366 | |
| 367 | def floor(self, label: int) -> int | None: |
| 368 | """Returns the largest element in this tree which is at most label. |
| 369 | This method is guaranteed to run in O(log(n)) time.""" |
| 370 | if self.label == label: |
| 371 | return self.label |
| 372 | elif self.label is not None and self.label > label: |
| 373 | if self.left: |
| 374 | return self.left.floor(label) |
| 375 | else: |
| 376 | return None |
| 377 | else: |
| 378 | if self.right: |
| 379 | attempt = self.right.floor(label) |
| 380 | if attempt is not None: |
| 381 | return attempt |
| 382 | return self.label |
| 383 | |
| 384 | def ceil(self, label: int) -> int | None: |
| 385 | """Returns the smallest element in this tree which is at least label. |
no outgoing calls