On 22.11.2017 07:22, Nick Timkovich wrote:
Functions are great. I'm a big fan of functions. However,
- Once there are several that all have the same thing as an argument:
thing_operation1(thing, arg), thing_operation2(thing, arg)...it's about time to bind them together. 2. And especially for the heap "soft-datatype": once it's heapified, naively modifying it with other methods will ruin the heap invariant. **The actual list you pass around can't be treated as a list.**
Two important aspects to which I want to add some thoughts.
The reason why I created xheap was because I actually needed a more complex datastructure which required more bookkeeping:
1) custom orders on the same data (list) 2) fast removal from within the heap
The plain "Heap" implementation (object wrapper of heapq) was just for the sake of completion.
PS: I tend to think that implementing xheap was easier BECAUSE the stdlib provided a function-only heap implementation. Nonetheless, both ways do have their merits.