MCPcopy
hub / github.com/networkx/networkx / pop

Method pop

networkx/utils/mapped_queue.py:189–205  ·  view source on GitHub ↗

Remove and return the smallest element in the queue.

(self)

Source from the content-addressed store, hash-verified

187 return True
188
189 def pop(self):
190 """Remove and return the smallest element in the queue."""
191 # Remove smallest element
192 elt = self.heap[0]
193 del self.position[elt]
194 # If elt is last item, remove and return
195 if len(self.heap) == 1:
196 self.heap.pop()
197 return elt
198 # Replace root with last element
199 last = self.heap.pop()
200 self.heap[0] = last
201 self.position[last] = 0
202 # Restore invariant by sifting up
203 self._siftup(0)
204 # Return smallest element
205 return elt
206
207 def update(self, elt, new, priority=None):
208 """Replace an element in the queue with a new one."""

Callers 3

test_popMethod · 0.95
removeMethod · 0.45

Calls 1

_siftupMethod · 0.95

Tested by 1

test_popMethod · 0.76