{"id":23390661,"url":"https://github.com/tompng/penguin_queue","last_synced_at":"2025-04-11T08:45:26.652Z","repository":{"id":56887776,"uuid":"82066669","full_name":"tompng/penguin_queue","owner":"tompng","description":"Ruby Priority Queue (C extention, binary heap)","archived":false,"fork":false,"pushed_at":"2017-03-25T07:15:00.000Z","size":58,"stargazers_count":4,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-25T06:14:15.264Z","etag":null,"topics":["ruby"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tompng.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-02-15T14:01:25.000Z","updated_at":"2019-03-27T15:42:11.000Z","dependencies_parsed_at":"2022-08-21T00:50:43.734Z","dependency_job_id":null,"html_url":"https://github.com/tompng/penguin_queue","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompng%2Fpenguin_queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompng%2Fpenguin_queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompng%2Fpenguin_queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tompng%2Fpenguin_queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tompng","download_url":"https://codeload.github.com/tompng/penguin_queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248362800,"owners_count":21091200,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ruby"],"created_at":"2024-12-22T03:42:19.800Z","updated_at":"2025-04-11T08:45:26.633Z","avatar_url":"https://github.com/tompng.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Penguin Queue\n\n[![Build Status](https://travis-ci.org/tompng/penguin_queue.svg?branch=master)](https://travis-ci.org/tompng/penguin_queue)\n\nRuby priority-queue library\n\n```ruby\n10000.times { array \u003c\u003c rand; array.delete(array.min) } #=\u003e slow when array.size is large\n10000.times { pq \u003c\u003c rand; pq.deq } #=\u003e fast even if pq.size is large\n```\n\n# Install\n```\ngem install penguin_queue\n```\n\n```ruby\n# Gemfile\ngem 'penguin_queue'\n```\n\n# Usage\n```ruby\nrequire 'penguin_queue'\npq = PenguinQueue.new\n10.times.to_a.shuffle.each { |i| pq \u003c\u003c i }\n10.times.map { pq.deq }  #=\u003e [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]\n\n# custom priority\npq.enq 'hello', priority: 0\npq.first #=\u003e \"hello\"\npq.first_with_priority #=\u003e [\"hello\", 0]\npq.deq_with_priority #=\u003e [\"hello\", 0]\n\n# update priority, remove node\nnodes = 10.times.to_a.shuffle.map { |i| pq \u003c\u003c i }\nnodes.each { |n| n.priority = -n.priority }\nnodes.each_with_index{ |n| n.remove if n.value.odd? }\npq.size.times.map { pq.deq } #=\u003e [8, 6, 4, 2, 0]\n```\n\n# Methods\n```ruby\n# initialize\nPenguinQueue.new\nPenguinQueue.new(order) # :min(default) or :max\nPenguinQueue.new(\u0026calc_priority_from_element_proc)\n# enqueue\n\u003c\u003c(e) enq(e) push(e) unshift(e)\n# enqueue with custom priority\nenq(e, priority: p) push(e, priority: p) unshift(e, priority: e)\n# dequeue\ndeq shift pop poll deq_with_priority\n# dequeue multiple\ndeq(n) shift(n) pop(n) poll(n)\n# fetch\nfirst peek top first_with_priority first_node\n# remove\nremove(node) delete(node)\n# other\nto_s inspect clear size empty? min? max?\n\n# PenguinQueue::Node\nremove delete value value= priority priority= to_s inspect\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftompng%2Fpenguin_queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftompng%2Fpenguin_queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftompng%2Fpenguin_queue/lists"}