class_docstr: The MappedQueue class implements a min-heap with removal and update-priority.
  
  The min heap uses heapq as well as custom written _siftup and _siftdown
  methods to allow the heap positions to be tracked by an additional dict
  keyed by element to position. The smallest element can be popped in O(1) time,
  new elements can be pushed in O(log n) time, and any element can be removed
  or updated in O(log n) time. The queue cannot contain duplicate elements
  and an attempt to push an element already in the queue will have no effect.
  
  MappedQueue complements the heapq package from the python standard
  library. While MappedQueue is designed for maximum compatibility with
  heapq, it adds element removal, lookup, and priority update.
  
  Parameters
  ----------
  data : dict or iterable
  
  Examples
  --------
  
  A `MappedQueue` can be created empty, or optionally, given a dictionary
  of initial elements and priorities.  The methods `push`, `pop`,
  `remove`, and `update` operate on the queue.
  
  >>> colors_nm = {'red':665, 'blue': 470, 'green': 550}
  >>> q = MappedQueue(colors_nm)
  >>> q.remove('red')
  >>> q.update('green', 'violet', 400)
  >>> q.push('indigo', 425)
  True
  >>> [q.pop().element for i in range(len(q.heap))]
  ['violet', 'indigo', 'blue']
  
  A `MappedQueue` can also be initialized with a list or other iterable. The priority is assumed
  to be the sort order of the items in the list.
  
  >>> q = MappedQueue([916, 50, 4609, 493, 237])
  >>> q.remove(493)
  >>> q.update(237, 1117)
  >>> [q.pop() for i in range(len(q.heap))]
  [50, 916, 1117, 4609]
  
  An exception is raised if the elements are not comparable.
  
  >>> q = MappedQueue([100, 'a'])
  Traceback (most recent call last):
  ...
  TypeError: '<' not supported between instances of 'int' and 'str'
  
  To avoid the exception, use a dictionary to assign priorities to the elements.
  
  >>> q = MappedQueue({100: 0, 'a': 1 })
  
  References
  ----------
  .. [1] Cormen, T. H., Leiserson, C. E., Rivest, R. L., & Stein, C. (2001).
     Introduction to algorithms second edition.
  .. [2] Knuth, D. E. (1997). The art of computer programming (Vol. 3).
     Pearson Education.
class_docstr_tok: ["The","MappedQueue","class","implements","a","min-heap","with","removal","and","update-priority",".","The","min","heap","uses","heapq","as","well","as","custom","written","_siftup","and","_siftdown","methods","to","allow","the","heap","positions","to","be","tracked","by","an","additional","dict","keyed","by","element","to","position",".","The","smallest","element","can","be","popped","in","O","(","1",")","time",",","new","elements","can","be","pushed","in","O","(","log","n",")","time",",","and","any","element","can","be","removed","or","updated","in","O","(","log","n",")","time",".","The","queue","can","not","contain","duplicate","elements","and","an","attempt","to","push","an","element","already","in","the","queue","will","have","no","effect",".","MappedQueue","complements","the","heapq","package","from","the","python","standard","library",".","While","MappedQueue","is","designed","for","maximum","compatibility","with","heapq",",","it","adds","element","removal",",","lookup",",","and","priority","update",".","Parameters","--","--","--","--","--","data",":","dict","or","iterable","Examples","--","--","--","--","A","`","MappedQueue","`","can","be","created","empty",",","or","optionally",",","given","a","dictionary","of","initial","elements","and","priorities",".","The","methods","`","push","`",",","`","pop","`",",","`","remove","`",",","and","`","update","`","operate","on","the","queue",".",">",">",">","colors_nm","=","{","'red':665",",","'blue","'",":","470",",","'green","'",":","550","}",">",">",">","q","=","MappedQueue","(","colors_nm",")",">",">",">","q.remove","(","'red","'",")",">",">",">","q.update","(","'green","'",",","'violet","'",",","400",")",">",">",">","q.push","(","'indigo","'",",","425",")","True",">",">",">","[","q.pop","(",")",".element","for","i","in","range","(","len","(","q.heap",")",")","]","[","'violet","'",",","'indigo","'",",","'blue","'","]","A","`","MappedQueue","`","can","also","be","initialized","with","a","list","or","other","iterable",".","The","priority","is","assumed","to","be","the","sort","order","of","the","items","in","the","list",".",">",">",">","q","=","MappedQueue","(","[","916",",","50",",","4609",",","493",",","237","]",")",">",">",">","q.remove","(","493",")",">",">",">","q.update","(","237",",","1117",")",">",">",">","[","q.pop","(",")","for","i","in","range","(","len","(","q.heap",")",")","]","[","50",",","916",",","1117",",","4609","]","An","exception","is","raised","if","the","elements","are","not","comparable",".",">",">",">","q","=","MappedQueue","(","[","100",",","'","a","'","]",")","Traceback","(","most","recent","call","last",")",":","...","TypeError",":","'","<","'","not","supported","between","instances","of","'int","'","and","'str'","To","avoid","the","exception",",","use","a","dictionary","to","assign","priorities","to","the","elements",".",">",">",">","q","=","MappedQueue","(","{","100",":","0",",","'","a","'",":","1","}",")","References","--","--","--","--","--","..","[","1","]","Cormen",",","T.","H.",",","Leiserson",",","C.","E.",",","Rivest",",","R.","L.",",","&","Stein",",","C.","(","2001",")",".","Introduction","to","algorithms","second","edition",".","..","[","2","]","Knuth",",","D.","E.","(","1997",")",".","The","art","of","computer","programming","(","Vol",".","3",")",".","Pearson","Education","."]
docstr: Remove an element from the queue.
docstr_tok: ["Remove","an","element","from","the","queue","."]
code: def remove(self, elt):
      """Remove an element from the queue."""
      # Find and remove element
      try:
          pos = self.position[elt]
          del self.position[elt]
      except KeyError:
          # Not in queue
          raise
      # If elt is last item, remove and return
      if pos == len(self.heap) - 1:
          self.heap.pop()
          return
      # Replace elt with last element
      last = self.heap.pop()
      self.heap[pos] = last
      self.position[last] = pos
      # Restore invariant by sifting up
      self._siftup(pos)
  
file_path: networkx/networkx/utils/mapped_queue.py
imports: import heapq
label_desc: Use image node_id 7 for calling the MappedQueue obj's underlying member method code with example usage: obj.remove(elt) without return types