On 3/2/07, Adam Olsen <rhamph@gmail.com> wrote:
On 3/1/07, Jason Orendorff <jason.orendorff@gmail.com> wrote:
> I wonder if anyone else finds the heapq and bisect APIs a little dated.
> It seems like these things could be offered in a more intuitive and
> featureful way by making them classes. They could go in the
> collections module:
I agree, at least for heapq. The algorithm involves enough voodoo
that it's not obvious how to extend it, so it might as well be wrapped
in a class that hides as much as possible.
The same can't be said for bisect though. All it does is replace del
a[bisect_left(a, x)] with a.remove(x). A little cleaner, but no more
obvious. And the cost is still O(n) since it involves moving all the
pointers after x.