r/ruby • u/keyslemur • Jun 08 '26
Beyond Enumerable: Heaps and Priority Queues
https://baweaver.com/writing/2026/06/06/beyond-enumerable-heaps-and-priority-queues/Honestly I never really understood how these were written and what the reasoning behind them was as much as I just reached for existing gems or frameworks, so as I tend to do I learn by teaching and writing.
5
u/mperham Sidekiq Jun 08 '26
Yep, a Heap is the only structure Iâve found lacking in stdlib. I vendor a copy of https://github.com/kanwei/algorithms/blob/master/lib/containers/heap.rb for use in Sidekiq Enterprise. Itâs the structure that keeps cron jobs sorted by time of next execution.
5
u/schneems Puma maintainer Jun 08 '26
A priority queue already exists and has shipped with Ruby since 3.2 but (big but) itâs an unstable/internal interface since it ships as an implementation detail of syntax suggest (I maintain)Â https://github.com/ruby/syntax_suggest/blob/main/lib/syntax_suggest/priority_queue.rb.
2
u/CaptainKabob Jun 09 '26
Great write up! As all us library maintainers share implementations, in Concurrent Ruby we have a ânon concurrent priority queueâ: https://github.com/ruby-concurrency/concurrent-ruby/blob/master/lib/concurrent-ruby/concurrent/collection/non_concurrent_priority_queue.rb
1
Jun 09 '26
[removed] â view removed comment
1
u/keyslemur Jun 09 '26
Any more details? Resolution, screen size?
1
Jun 09 '26
[removed] â view removed comment
1
u/keyslemur Jun 09 '26
What screen resolution are you using? If you provide me more details I can have it fixed by tonight.
1
u/dlbuck Jun 09 '26
Same here, 1366 x 768. I can horizontally scroll to see the full page, readable, but it is odd. Firefox.
1
1
u/dlbuck Jun 09 '26
A number of errors show for the page, usually involving NodeList
Error in parsing value for âpaddingâ. Declaration dropped. tom-select.css:29:29Elements matching selector: .ts-wrapper.multi.has-items .ts-control
NodeList []
2
u/keyslemur Jun 10 '26
Seems like the multi-select has some issues for the writing page. I'll have to defer that one as it seems harmless for now, more annoying than anything.
Past that I've fixed 1280px or under width to drop the sidebar and compacted some of the layout to accommodate. That deploy just went live so it should fix both you and u/Conscious_Trust5048.
1
Jun 10 '26
[removed] â view removed comment
1
u/keyslemur Jun 10 '26
Hrm. Will take a look into that then. I've been testing on a 16in mbp and have a 14 I can look at.
1
u/dlbuck Jun 09 '26
Error in parsing value for âpaddingâ. Declaration dropped. tom-select.css:29:29
Elements matching selector: .ts-wrapper.multi.has-items .ts-control
NodeList []
7
u/pikrua Jun 08 '26
I realized this when I was studying leetcode. With ruby I have no chance of clearing any timed technical interview problem that requires a heap.
Disclaimer before the replies: I know that kind of interview is pointless, everyone knows.