
Security News
New React Server Components Vulnerabilities: DoS and Source Code Exposure
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.
A very fast and tiny binary heap priority queue in JavaScript.
Similar to tinyqueue, but stores the queue as two flat arrays of items and their numeric priority values respectively (without a way to specify a comparator function). This makes the queue more limited, but several times faster.
const q = new FlatQueue();
for (let i = 0; i < items.length; i++) {
// Push an item index and its priority value. You can push other values as well,
// but storing only integers is much faster due to JavaScript engine optimizations.
q.push(i, items[i].priority);
}
q.peekValue(); // Read the top item's priority value
q.peek(); // Read the top item
q.pop(); // Remove and return the top item
Install with npm install flatqueue, then use as a module:
import FlatQueue from 'flatqueue';
Alternatively, use as a module in a browser directly:
<script type="module">
import FlatQueue from 'https://cdn.jsdelivr.net/npm/flatqueue/+esm';
There's also a UMD bundle that exposes a global FlatQueue global variable:
<script src="https://cdn.jsdelivr.net/npm/flatqueue"></script>
new FlatQueue()Creates an empty queue object with the following methods and properties:
push(item, priority)Adds item to the queue with the specified priority.
priority must be a number. Items are sorted and returned from low to high priority.
Multiple items with the same priority value can be added to the queue, but the queue is not stable
(items with the same priority are not guaranteed to be popped in iteration order).
pop()Removes and returns the item from the head of this queue, which is one of the items with the lowest priority.
If this queue is empty, returns undefined.
peek()Returns the item from the head of this queue without removing it.
If this queue is empty, returns undefined.
peekValue()Returns the priority value of the item at the head of this queue without removing it.
If this queue is empty, returns undefined.
clear()Removes all items from the queue.
shrink()Shrinks the internal arrays to this.length.
pop() and clear() calls don't free memory automatically to avoid unnecessary resize operations.
This also means that items that have been added to the queue can't be garbage collected
until a new item is pushed in their place, or this method is called.
lengthNumber of items in the queue. Read-only.
idsAn underlying array of items. Note that it can be bigger than the length as it's not eagerly cleared.
valuesAn underlying array of priority values. Note that it can be bigger than the length as it's not eagerly cleared.
If 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 library.
const q = new FlatQueue();
q.ids = new Uint16Array(32);
q.values = new Uint32Array(32);
FAQs
The smallest and simplest JavaScript priority queue
The npm package flatqueue receives a total of 176,902 weekly downloads. As such, flatqueue popularity was classified as popular.
We found that flatqueue demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.

Security News
GitHub has revoked npm classic tokens for publishing; maintainers must migrate, but OpenJS warns OIDC trusted publishing still has risky gaps for critical projects.