Using heapq functions on a list can be easily misused, forgetting to re-heapify the structure when manipulation is done done without using heapq functions, or using the regular pop() inadvertently.
We already have at least one instance of this causing an obscure bug in the [dispatch library](https://github.com/frequenz-floss/frequenz-dispatch-python/, which could have easily prevented if we had this kind of abstraction.
For that particular case we would need to provide a way to get an element an arbitrary index, by keeping the heap a heap. We should properly document that this could be an expensive operation though.
Coming from a post by @llucax in frequenz-floss/frequenz-dispatch-python#246 (comment)
Using
heapqfunctions on alistcan be easily misused, forgetting to re-heapify the structure when manipulation is done done without usingheapqfunctions, or using the regularpop()inadvertently.We already have at least one instance of this causing an obscure bug in the [dispatch library](https://github.com/frequenz-floss/frequenz-dispatch-python/, which could have easily prevented if we had this kind of abstraction.
For that particular case we would need to provide a way to get an element an arbitrary index, by keeping the heap a heap. We should properly document that this could be an expensive operation though.
Coming from a post by @llucax in frequenz-floss/frequenz-dispatch-python#246 (comment)