Esempio n. 1
0
 def __init__(self,
              items = (),
              entries = (),
              key = lambda x: x):
     self._key = key
     self._entries = [Entry(i, p) for i, p in entries]
     self._entries.extend([Entry(i, key(i)) for i in items])
     self._itemmap = {entry.item : index
                      for index, entry in enumerate(self._entries)}
     self._heapify()
Esempio n. 2
0
 def insert(self, item, priority = None):
     if priority is None:
         priority = self._key(item)
     index = len(self._entries)
     self._entries.append(Entry(item, priority))
     self._itemmap[item] = index
     self._upheap(index)
Esempio n. 3
0
 def insert(self, item, priority):
     self._entries.append(Entry(item, priority))
     self._entries.sort(reverse = True)
Esempio n. 4
0
 def insert(self, item, priority):
     self._entries.append(Entry(item, priority))
     self._upheap(len(self._entries) - 1)
Esempio n. 5
0
 def insert(self, item, priority):
     self._entries.append(Entry(item, priority))