
Priorityq – Another python priority queue library - flashgordon
https://panyam.wordpress.com/2017/02/14/priorityq/
======
asmanikabutar
This is great! I've not looked at the code, but Java PQ didn't do O(1) find
either. What were the trade-offs to get O(1) finds?

~~~
flashgordon
The short answer is that I decoupled the actual heap storage from the PQ api
that uses the heap storage so that I keep a map of values to handles (as
returned by the storage).

Consider the python heapq module. It directly works on a list, maintaining the
heap invariant. So you (the dev) can freely modify the underlying list
invalidating the heap invariant. But if the (heap) storage returned handle
objects that encapsulated the position within the heap, then the client can
just update the priority of the value pointed by the handle without knowing
anything about how the heap is implemented.

So linear increase in memory usage (for the map) but fast retrievals. I plan
to try this out with other kinds of heap implementations soon.

------
flashgordon
Was shocked to find that Python's _heapq_ module does not have a way to find
(in constant time) or delete or update values. So I developed priorityq to
provide these missing features and much more.

Would love to get some feedback.

