{"id":20200496,"url":"https://github.com/jakzo/priority-queue","last_synced_at":"2025-11-30T11:05:35.653Z","repository":{"id":100510606,"uuid":"84916373","full_name":"jakzo/priority-queue","owner":"jakzo","description":"JavaScript priority queue implementation.","archived":false,"fork":false,"pushed_at":"2017-03-15T08:03:05.000Z","size":21,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-01-13T20:14:34.384Z","etag":null,"topics":["computer-science","data-structures"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"cc0-1.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jakzo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-03-14T07:00:04.000Z","updated_at":"2017-12-15T03:32:08.000Z","dependencies_parsed_at":"2023-03-08T01:15:45.327Z","dependency_job_id":null,"html_url":"https://github.com/jakzo/priority-queue","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakzo%2Fpriority-queue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakzo%2Fpriority-queue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakzo%2Fpriority-queue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jakzo%2Fpriority-queue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jakzo","download_url":"https://codeload.github.com/jakzo/priority-queue/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241637184,"owners_count":19994926,"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":["computer-science","data-structures"],"created_at":"2024-11-14T04:44:07.391Z","updated_at":"2025-11-30T11:05:30.618Z","avatar_url":"https://github.com/jakzo.png","language":"JavaScript","readme":"# priority-queue\n[![Build Status](https://travis-ci.org/jakzo/priority-queue.svg?branch=master)](https://travis-ci.org/jakzo/priority-queue)\n[![Build status](https://ci.appveyor.com/api/projects/status/ov5yyh5r827nwip1?svg=true)](https://ci.appveyor.com/project/jakzo/priority-queue)\n[![Coverage Status](https://coveralls.io/repos/github/jakzo/priority-queue/badge.svg?branch=master)](https://coveralls.io/github/jakzo/priority-queue?branch=master)\n[![Dependency Status](https://dependencyci.com/github/jakzo/priority-queue/badge)](https://dependencyci.com/github/jakzo/priority-queue)\n\n*JavaScript priority queue implementation.*\n\n## Usage\n\n```js\n// Include the library\n// Browser: \u003cscript type=\"text/javascript\" src=\"./lib/priority-queue.js\"\u003e\u003c/script\u003e\n// Node:    var PriorityQueue = require('./lib/priority-queue.js')\n// ES6:     import PriorityQueue from './lib/priority-queue.js'\n\nfunction compare(a, b) {\n  if (a.priority \u003c b.priority) return true;\n  return false;\n}\nvar pq = new PriorityQueue(compare);\npq.push({ foo: 'bar', priority: 4 });\npq.push({ priority: 3, something: 'text' });\npq.push({ priority: 9 });\nconsole.log(pq.length); // 3\nconsole.log(pq.pop());  // { priority: 3, something: 'text' }\nconsole.log(pq.peek()); // { foo: 'bar', priority: 4 }\nconsole.log(pq.pop());  // { foo: 'bar', priority: 4 }\nconsole.log(pq.pop());  // { priority: 9 }\n```\n\n## API\n\n\n### Class: `PriorityQueue`\n\n#### `push(item)`\n\nPushes an element onto the queue.\n\n**item**: `*`, Element to be pushed onto the queue.\n\n**Returns**: `number`, The number of items on the queue after the push.\n\n#### `pop()`\n\nRemoves and returns the item with the highest priority.\n\n**Returns**: `*`, The item with the highest priority in the queue.\n\n#### `peek()`\n\nReturns the item with the highest priority without removing it.\n\n**Returns**: `*`, The item with the highest priority in the queue.\n\n#### `clear()`\n\nRemoves all elements from the queue.\n\n**Returns**: `void`\n\n#### `length`\n\nThe number of elements in the queue.\n\n**Type**: `number`\n\n#### `PriorityQueue.defaultCompare`\n\nThe comparison function which is used if no comparison function is passed\ninto the constructor. By default it evaluates `a \u003c b`.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakzo%2Fpriority-queue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjakzo%2Fpriority-queue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjakzo%2Fpriority-queue/lists"}