@nxtedition/fixed-queue
v1.0.3
Published
Fast FIFO queue backed by a singly-linked list of fixed-size circular buffers. Adapted from Node.js's internal `fixed_queue.js`.
Maintainers
Keywords
Readme
@nxtedition/fixed-queue
Fast FIFO queue backed by a singly-linked list of fixed-size circular buffers. Adapted from Node.js's internal fixed_queue.js.
Buffers are pooled and reused after becoming empty, so the queue does minimal allocation work under steady-state push/shift loads.
Install
npm install @nxtedition/fixed-queueUsage
import { FixedQueue } from '@nxtedition/fixed-queue'
const q = new FixedQueue()
q.push('a')
q.push('b')
q.shift() // 'a'
q.shift() // 'b'
q.shift() // null
q.isEmpty() // trueAPI
new FixedQueue()
Create an empty queue.
push(data)
Append an item. Throws TypeError if data is undefined (sentinel value used to detect empty slots).
shift()
Remove and return the oldest item. Returns null if the queue is empty.
isEmpty()
true if the queue is empty.
License
MIT
