Is there a binary heap implementation where I can pop other elements than the root in log n time?
I use heapq - but heap.index( wKeys ) in
heap.pop( heap.index( wKeys ) )
is very slow. I need a binary heap for my problem - where I sometime use
heapq.heappop(heap)
but also need to pop other elements than at the top from the heap. So a binary heap like heapq imlementation should do that but I havnt found a binary search method. I also looked at treap (http://stromberg.dnsalias.org/~strombrg/treap/) and cannot find a method like this here either.
wKeys? In general, I wouldn't expect finding the index of a specific member would be fast - though my comp sci is pretty rusty. Ref docs.python.org/3.5/library/… it seems that "how do you find [an item] and remove it from the queue?" is an open problem, though it suggests a solution there. I think in general what you want to do isn't a 'built-in' property of a binary heap.treaphas some additional implementation (such as the 'addon' dictionary) that makes lookup efficient, but that will come at the code of additional operations on push/pop and additional storage cost.