On Fri, Mar 28, 2014 at 09:20:35AM +0000, Kristján Valur Jónsson wrote: > I'll be willing to experiment with extending the heapq. methods to take an > optional "map" argument. > 'map' would be a dict, mapping objects in the heap to indices. If provided, > each of the heapq methouds would > take care to update the map of any objects that it touches with the current > index of the object. > > Usage could be something like: > > heap = [] > map = {} > def insert(i): > heapq.heappush(heap, I, map) > > def pop(i): > return heapq.heappop(heap, map) > > def remove(i): > heapq.heapdel(heap, map[i], map)
If you're going to make heapq more complex, wouldn't it be better to encapsulate the logic into a Heap class? heapq should remain the same, and Heap could (if accepted) move into collections. And should this discussion move to python-ideas? -- Steven _______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com