[issue31186] Support heapfix() and heapremove() APIs in heapq module

2017-08-13 Thread Rajath Agasthya
Rajath Agasthya added the comment: And yes, both of these methods do take index as the argument as shown in my patch file. I should've probably specified that. The signatures are: heapfix(heap, pos) heapremove(heap, pos) -- ___ Python tracker

[issue31186] Support heapfix() and heapremove() APIs in heapq module

2017-08-13 Thread Rajath Agasthya
Rajath Agasthya added the comment: > The only hacks around that I could think of required a more complex kind of > heap; e.g., restricting heap items to objects usable as dict keys, using a > hidden dict to map heap items to their current index, and fiddling all the > heap operations to keep

[issue31186] Support heapfix() and heapremove() APIs in heapq module

2017-08-13 Thread Tim Peters
Tim Peters added the comment: @Rajath, I suspect Raymond may have been bamboozled because your suggested `heapfix()` and `heapremove()` didn't appear to take any arguments. If the index is a required argument, then these are O(log N) operations. I thought about adding them years ago, but

[issue31186] Support heapfix() and heapremove() APIs in heapq module

2017-08-13 Thread Rajath Agasthya
Rajath Agasthya added the comment: Thanks, Raymond. I think it's fair comment, but I'm not sure which operation is O(n) though. FWIW, Go supports these operations (https://golang.org/pkg/container/heap/), so the usage is there. -- ___ Python

[issue31186] Support heapfix() and heapremove() APIs in heapq module

2017-08-12 Thread Raymond Hettinger
Raymond Hettinger added the comment: -1 I don't think this is the right way to use heaps. Also, I don't want to introduce any O(n) operations for fine-grained changes of a single element (part of the point of having a heap is to make fine-grained changes cheap). FWIW, it isn't common to

[issue31186] Support heapfix() and heapremove() APIs in heapq module

2017-08-12 Thread Raymond Hettinger
Changes by Raymond Hettinger : -- assignee: -> rhettinger ___ Python tracker ___

[issue31186] Support heapfix() and heapremove() APIs in heapq module

2017-08-11 Thread Rajath Agasthya
New submission from Rajath Agasthya: I'd like to suggest a couple of utility methods for the heapq module which I think are useful: 1. heapfix() - Re-establishes heap invariant after item at 'any index' in the heap changes its value. Currently, the way to fix the heap after an arbitrary item