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()
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)
def insert(self, item, priority): self._entries.append(Entry(item, priority)) self._entries.sort(reverse = True)
def insert(self, item, priority): self._entries.append(Entry(item, priority)) self._upheap(len(self._entries) - 1)
def insert(self, item, priority): self._entries.append(Entry(item, priority))