MCPcopy
hub / github.com/networkx/networkx / remove

Method remove

networkx/utils/mapped_queue.py:219–237  ·  view source on GitHub ↗

Remove an element from the queue.

(self, elt)

Source from the content-addressed store, hash-verified

217 self._siftup(pos)
218
219 def remove(self, elt):
220 """Remove an element from the queue."""
221 # Find and remove element
222 try:
223 pos = self.position[elt]
224 del self.position[elt]
225 except KeyError:
226 # Not in queue
227 raise
228 # If elt is last item, remove and return
229 if pos == len(self.heap) - 1:
230 self.heap.pop()
231 return
232 # Replace elt with last element
233 last = self.heap.pop()
234 self.heap[pos] = last
235 self.position[last] = pos
236 # Restore invariant by sifting up
237 self._siftup(pos)
238
239 def _siftup(self, pos):
240 """Move smaller child up until hitting a leaf.

Callers 15

test_remove_leafMethod · 0.80
test_remove_rootMethod · 0.80
test_subMethod · 0.80
test_subMethod · 0.80
_neighbor_switchFunction · 0.80
add_nodeMethod · 0.80
add_m_peering_linkMethod · 0.80
add_cp_peering_linkMethod · 0.80

Calls 2

_siftupMethod · 0.95
popMethod · 0.45

Tested by 10

test_remove_leafMethod · 0.64
test_remove_rootMethod · 0.64
test_subMethod · 0.64
test_subMethod · 0.64
test_karate_clubFunction · 0.64