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
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4