🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
DemoInstallSign in
Socket

binary_heap

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

binary_heap

0.1.1
Rubygems
Version published
Maintainers
1
Created
Source

BinaryHeap

BinaryHeap is a pure ruby implementation of a binary heap, that can be used as a priority queue.

Installation

Install the gem and add to the application's Gemfile by executing:

$ bundle add binary_heap

If bundler is not being used to manage dependencies, install the gem by executing:

$ gem install binary_heap

Usage


    require 'binary_heap'
    q = BinaryHeap::Base.new([4,5,7])
    q.push(2)  
    q.min # => 2
    q.pop # => 2
    q.min # => 4

Benchmarks

On modern Ruby (>= 3.2) with YJIT enabled it is about as fast as priority_queue_cxx which is a Heap Implementation written as a C++-Extension to Ruby. In any case it compares favorably against other heap implementations written in pure Ruby.

Libraryusersystemtotalreal
binary_heap3.0895220.0050003.094522( 3.094816)
priority_queue_cxx0.7269670.0000000.726967( 0.726975)
lazy-priority-queue10.6464690.03299610.679465( 10.681288)

With YJIT enabled:

Libraryusersystemtotalreal
binary_heap0.6979220.0039810.701903( 0.702160)
priority_queue_cxx0.7079530.0010050.708958( 0.708970)
lazy-priority-queue5.4569120.0270235.483935( 5.484204)

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/skr0504/binary_heap.

FAQs

Package last updated on 06 Mar 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts