Socket
Socket
Sign inDemoInstall

fast-fifo

Package Overview
Dependencies
0
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    fast-fifo

A fast fifo implementation similar to the one powering nextTick in Node.js core


Version published
Weekly downloads
6M
Maintainers
1
Install size
4.95 kB
Created
Weekly downloads
 

Package description

What is fast-fifo?

The fast-fifo npm package is a high-performance, zero-dependency queue implementation for JavaScript. It is designed to be a fast FIFO (first-in-first-out) queue structure that can be used in various scenarios where queue operations are required, such as task scheduling, event handling, or data processing pipelines.

What are fast-fifo's main functionalities?

Queue Creation

This feature allows for the creation of a new queue instance. The Queue class is imported from the fast-fifo package and instantiated to create a new queue.

const Queue = require('fast-fifo');
const q = new Queue();

Enqueue

This feature is used to add an item to the end of the queue. The push method is called on the queue instance with the item to be added as an argument.

q.push('some data');

Dequeue

This feature is used to remove and return the item at the front of the queue. The shift method is called on the queue instance to dequeue the item.

const item = q.shift();

Peek

This feature allows you to look at the item at the front of the queue without removing it. The head method is called on the queue instance to retrieve the first item.

const firstItem = q.head();

Queue Length

This feature provides the current number of items in the queue. The length property of the queue instance gives the count of items.

const queueLength = q.length;

Other packages similar to fast-fifo

Readme

Source

fast-fifo

A fast fifo implementation similar to the one powering nextTick in Node.js core

npm install fast-fifo

Uses a linked list of growing fixed sized arrays to implement the FIFO to avoid allocating a wrapper object for each item.

Usage

const FIFO = require('fast-fifo')

const q = new FIFO()

q.push('hello')
q.push('world')

q.shift() // returns hello
q.shift() // returns world

API

q = new FIFO()

Create a new FIFO.

q.push(value)

Push a value to the FIFO. value can be anything other than undefined.

value = q.shift()

Return the oldest value from the FIFO.

q.clear()

Remove all values from the FIFO.

bool = q.isEmpty()

Returns true if the FIFO is empty and false otherwise.

value = q.peek()

Return the oldest value from the FIFO without shifting it out.

len = q.length

Get the number of entries remaining in the FIFO.

Benchmarks

Included in bench.js is a simple benchmark that benchmarks this against a simple linked list based FIFO.

On my machine the benchmark looks like this:

fifo bulk push and shift: 2881.508ms
fifo individual push and shift: 3248.437ms
fast-fifo bulk push and shift: 1606.972ms
fast-fifo individual push and shift: 1328.064ms
fifo bulk push and shift: 3266.902ms
fifo individual push and shift: 3320.944ms
fast-fifo bulk push and shift: 1858.307ms
fast-fifo individual push and shift: 1516.983ms

YMMV

License

MIT

FAQs

Last updated on 21 Aug 2023

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc