Add an element to the queue.
(self, elt)
| 70 | raise AssertionError("Heap contains duplicate elements") |
| 71 | |
| 72 | def push(self, elt): |
| 73 | """Add an element to the queue.""" |
| 74 | # If element is already in queue, do nothing |
| 75 | if elt in self.d: |
| 76 | return False |
| 77 | # Add element to heap and dict |
| 78 | pos = len(self.h) |
| 79 | self.h.append(elt) |
| 80 | self.d[elt] = pos |
| 81 | # Restore invariant by sifting down |
| 82 | self._siftdown(pos) |
| 83 | return True |
| 84 | |
| 85 | def pop(self): |
| 86 | """Remove and return the smallest element in the queue.""" |
no test coverage detected