Comment

Comment by Lio

Nice. This is interesting and definitely something worth implementing. I hope you don't mind but I have some discussion points.

If it were me, rather than monkey patching array I'd be tempted introduce a new dedicated Heap class that implements existing API (push, pop, <<, shift) so that it's closer to existing Array and Queue implementations instead of adding dedicated heap_push, heap_pop, etc..

As well as better duck typing this allows introspection via .is_a? and case statements.

Also I wonder if it would be useful to base the implementation on the Queue[1] rather than Array to maintain thread safety.

1. https://ruby-doc.org/core-2.5.0/Queue.html

parent Lio 2 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton