{"id":13817388,"url":"https://github.com/mourner/flatqueue","last_synced_at":"2025-04-05T01:08:27.072Z","repository":{"id":31609842,"uuid":"128411963","full_name":"mourner/flatqueue","owner":"mourner","description":"A very fast and simple JavaScript priority queue","archived":false,"fork":false,"pushed_at":"2022-03-30T14:46:48.000Z","size":33,"stargazers_count":135,"open_issues_count":2,"forks_count":7,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-29T00:11:17.726Z","etag":null,"topics":["algorithms","binary-heap","data-structures","javascript","priority-queue"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mourner.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}},"created_at":"2018-04-06T15:21:32.000Z","updated_at":"2025-03-07T02:38:04.000Z","dependencies_parsed_at":"2022-08-07T16:30:36.714Z","dependency_job_id":null,"html_url":"https://github.com/mourner/flatqueue","commit_stats":null,"previous_names":[],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mourner%2Fflatqueue","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mourner%2Fflatqueue/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mourner%2Fflatqueue/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mourner%2Fflatqueue/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mourner","download_url":"https://codeload.github.com/mourner/flatqueue/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247271532,"owners_count":20911587,"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":["algorithms","binary-heap","data-structures","javascript","priority-queue"],"created_at":"2024-08-04T06:00:41.642Z","updated_at":"2025-04-05T01:08:27.056Z","avatar_url":"https://github.com/mourner.png","language":"JavaScript","readme":"# flatqueue\n\nA very fast and tiny binary heap priority queue in JavaScript.\n\nSimilar to [tinyqueue](https://github.com/mourner/tinyqueue/),\nbut stores the queue as two flat arrays of items and their numeric priority values respectively\n(without a way to specify a comparator function).\nThis makes the queue more limited, but several times faster.\n\n[![Build Status](https://github.com/mourner/flatqueue/workflows/Node/badge.svg?branch=master)](https://github.com/mourner/flatqueue/actions)\n[![Minzipped Size](https://badgen.net/bundlephobia/minzip/flatqueue)](https://esm.run/flatqueue)\n[![Simply Awesome](https://img.shields.io/badge/simply-awesome-brightgreen.svg)](https://github.com/mourner/projects)\n\n## Usage\n\n```js\nconst q = new FlatQueue();\n\nfor (let i = 0; i \u003c items.length; i++) {\n    // Push an item index and its priority value. You can push other values as well,\n    // but storing only integers is much faster due to JavaScript engine optimizations.\n    q.push(i, items[i].priority);\n}\n\nq.peekValue(); // Read the top item's priority value\nq.peek(); // Read the top item\nq.pop(); // Remove and return the top item\n```\n\n## Install\n\nInstall with `npm install flatqueue`, then use as a module:\n\n```js\nimport FlatQueue from 'flatqueue';\n```\n\nAlternatively, use as a module in a browser directly:\n\n```html\n\u003cscript type=\"module\"\u003e\n    import FlatQueue from 'https://cdn.jsdelivr.net/npm/flatqueue/+esm';\n```\n\nThere's also a UMD bundle that exposes a global `FlatQueue` global variable:\n\n```html\n\u003cscript src=\"https://cdn.jsdelivr.net/npm/flatqueue\"\u003e\u003c/script\u003e\n```\n\n## API\n\n### `new FlatQueue()`\n\nCreates an empty queue object with the following methods and properties:\n\n### `push(item, priority)`\n\nAdds `item` to the queue with the specified `priority`.\n\n`priority` must be a number. Items are sorted and returned from low to high priority.\nMultiple items with the same priority value can be added to the queue, but the queue is not stable\n(items with the same priority are not guaranteed to be popped in iteration order).\n\n### `pop()`\n\nRemoves and returns the item from the head of this queue, which is one of the items with the lowest priority.\nIf this queue is empty, returns `undefined`.\n\n### `peek()`\n\nReturns the item from the head of this queue without removing it.\nIf this queue is empty, returns `undefined`.\n\n### `peekValue()`\n\nReturns the priority value of the item at the head of this queue without removing it.\nIf this queue is empty, returns `undefined`.\n\n### `clear()`\n\nRemoves all items from the queue.\n\n### `shrink()`\n\nShrinks the internal arrays to `this.length`.\n\n`pop()` and `clear()` calls don't free memory automatically to avoid unnecessary resize operations.\nThis also means that items that have been added to the queue can't be garbage collected\nuntil a new item is pushed in their place, or this method is called.\n\n### `length`\n\nNumber of items in the queue. Read-only.\n\n### `ids`\n\nAn underlying array of items. Note that it can be bigger than the `length` as it's not eagerly cleared.\n\n### `values`\n\nAn underlying array of priority values. Note that it can be bigger than the `length` as it's not eagerly cleared.\n\n### Using typed arrays\n\nIf you know the maximum queue size beforehand, you can override the queue to use typed arrays for better performance and memory footprint. This makes it match the performance of the popular [heapify](https://github.com/luciopaiva/heapify) library.\n\n```js\nconst q = new FlatQueue();\nq.ids = new Uint16Array(32);\nq.values = new Uint32Array(32);\n```\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmourner%2Fflatqueue","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmourner%2Fflatqueue","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmourner%2Fflatqueue/lists"}