npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

simple-fifo-queue

v1.0.2

Published

When I need a software implementation of a queue, I don't want any overcomplicated module. I just need a light, simple and efficient code. If you want the same think, well nice, I made one.

Downloads

12

Readme

Queue

"Queue" is a simple queue class. This module is easy to use, light, small and has minimum dependencies.

The module is written in TypeScript and compiled into commonJS.

This is not any high-tech code. It is not dependent on 27182818284 modules and does not offer unseen JavaScript magic. Download this, save 10 minutes of your time and use it to create something awesome and efficient. We #keepItSimple.

Download

You can download the module on GitHub/simple-fifo-queue or using npm/simple-fifo-queue service.

npm install simple-fifo-queue --save

Queue - What is that?

Queue is a way to queue your actions, data or whatever. You will probably use a queue of some sort in BFS path searching algoritms.

Queue is FIFO (first-in, first-out) structure. Queue remembers all added values in its inserted order. You can pick up the first and the last added element, delete the first (front) element and push a new element, at the end of the queue.


//Create a queue
var queue = new Queue();

//> Queue status:
//-----queue empty-----

//Push a number
queue.Push(10);

//> Queue status:
// |FRONT| 10 |BACK|

//Push a number
queue.Push(16);

//> Queue status:
// |FRONT| 10---16 |BACK|

//Push a number
queue.Push(1);

//> Queue status:
// |FRONT| 10---16---1 |BACK|

//Get the front number
var numberFront = queue.Front(); // == 10

//Get the back number
var numberBack = queue.Back(); // == 1

//Pop the front number
queue.Pop();

//> Queue status:
// |FRONT| 16---1 |BACK|

Summary: This software implementation of queue is very useful in specific situations and algorithms, but you probably won't use it in everyday code.

Usage

Import and create new queue

You can import the module using import keyword or require function. In TypeScript, the Queue class is a generic class ("<>" thingies).

import { Queue } from "simple-fifo-queue";

//Instantiate new and empty Queue
var queue = new Queue();

//For TypeScript programmers: Queue is a generic class, so declaration in TypeScript would look like:
let queue = new Queue<string>(); //<string> or whatever data type you want to store and work with
var Q = require("simple-fifo-queue");

//Instantiate new and empty Queue
var queue = new Q.Queue();

Queue

Class Queue does not come with an iterator, because that would go against its logic.

All method have constant complexity O(1) (the best one).

Working with the Queue is easy. Here are all implemented methods:


//Instantiate new and empty Queue
var queue = new Queue();

queue.Front(); //Returns the element in the front
//Returns "null" if the queue is empty

queue.Back(); //Returns the element in the back
//Returns "null" if the queue is empty

queue.Pop(); //Removes the element in the front

queue.Push(); //Pushes a new element in the back

More examples

There is a testing file included in this module ("simple-fifo-queue/tests/queue_tests.ts" for TypeScript or "simple-fifo-queue/dist/tests/queue_tests.js" for JavaScript). You may find few useful examples there.


Sorry for my English, I hope it's readable.