(This has been discussed over a year ago, but people failed to reach a consensus in that thread, so I'm bringing it up again.)
Currently, min-heaps have an awkward implementation. IMHO It's
- Confusing. The name
BinaryHeapdoes not suggest it's a max-heap. To mix things up, other popular languages like Python and Java uses min-heaps by default.
- Inconvenient. There is a mental overhead to remember to call
Reverseeach time you
pop. Note that this cannot be addressed by using a separate crate, which is even more inconvenient than typing
- Error-prone. If (when) you forget one of the
Reverse, the code would still compile and you can hardly notice it. While this is a logical error which the compiler has no responsibility to detect, wouldn't it be great if we could prevent that with a minimal change to the standard library?
I believe min-heaps are used extensively enough to warrant their own name, so here is my proposal
MaxHeap. To keep backward compatibility, we can add a
pub use binary_heap::MaxHeap as BinaryHeap;in
BinaryHeap<Reverse<T>>and expose it as
What are your thoughts?