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

@pxtrick/queues

v0.0.7

Published

A Queue factory for creating various Queue data structures.

Downloads

2

Readme

Queues

A JavaScript module providing the implementations of various Queue data structures.

Simple Queue

A simple (first-in, first-out) Queue. Items are removed in the order in which they were added.

Methods

  • push(item) - Adds a new item to the Queue.
  • pop() - Removes and returns the next item from the Queue.
  • peek() - Returns, but does not remove, the next item in the Queue.
  • size() - Returns the number of items in the Queue.
  • empty() - Empties the Queue of all items.

Sample Usage

// Load the Queue factory.
var Queues = require('@pxtrick/Queues');

// Create a new (FIFO) Queue object.
var queue = Queues.newSimpleQueue();
queue.push( {id:'firstItem'} );
queue.push( {id:'secondItem'} );
queue.push( {id:'thirdItem'} );
queue.size();  // 3

queue.pop();  // 'firstItem'
queue.pop();  // 'secondItem'
queue.pop();  // 'thirdItem'

Stack

A simple (last-in, first-out) Stack. Items are removed in the reverse order in which they were added.

Methods

  • push(item) - Adds a new item to the Queue.
  • pop() - Removes and returns the next item from the Queue.
  • peek() - Returns, but does not remove, the next item in the Queue.
  • size() - Returns the number of items in the Queue.
  • empty() - Empties the Queue of all items.

Sample Usage

// Load the Queue factory.
var Queues = require('@pxtrick/Queues');

// Create a new Stack object.
var stack = Queues.newStack();
stack.push( {id:'firstItem'} );
stack.push( {id:'secondItem'} );
stack.push( {id:'thirdItem'} );

stack.pop();  // 'thirdItem'
stack.pop();  // 'secondItem'
stack.pop();  // 'firstItem'

Priority Queue

A Queue in which items are stored sorted by priority, and which are removed in the order of highest priority. NOTE: Larger numerical values will have a higher priority than smaller values. It is possible to create a custom comparator function (specific to sorting your own data) and pass it to the factory function: Queues.newPriorityQueue(customComparator).

Methods

  • push(item) - Adds a new item to the Queue.
  • pop() - Removes and returns the next highest priority item from the Queue.
  • peek() - Returns, but does not remove, the next highest priority item in the Queue.
  • size() - Returns the number of items in the Queue.
  • empty() - Empties the Queue of all items.

Sample Usage

// Load the Queue factory.
var Queues = require('@pxtrick/Queues');

// Create a new Priority Queue object.
var priorityQueue = Queues.newPriorityQueue();
priorityQueue.push( {name:'Priority 2', priority:2} );
priorityQueue.push( {name:'Priority 4', priority:4} );
priorityQueue.push( {name:'Priority 1', priority:1} );
priorityQueue.push( {name:'Priority 3', priority:3} );

priorityQueue.pop();  // 'Priority 4'
priorityQueue.pop();  // 'Priority 3'
priorityQueue.pop();  // 'Priority 2'
priorityQueue.pop();  // 'Priority 1'

Circular Queue

A Queue in which items can be iterated in a circular fashion. i.e when the "end" of the queue is encountered, the next item will be the one positioned at the "start" of the queue.

Methods

  • push(item) - Adds a new item to the end of the Queue, regardless of the iterator position.
  • next() - Returns, but does not remove, the next item in the Queue. This also advances the iterator position. (Useful for read-only iterating over a fixed set of items.)
  • pop() - Removes and returns the next item in the Queue.
  • peek() - Returns, but does not remove, the next item in the Queue. This does not advance the iterator position
  • setIndex(value) - Moves the iterator to the given index value. Values outside of the Queue bounds are ignored.
  • reset() - Moves the iterator to the first index in the Queue.
  • size() - Returns the number of items in the Queue.
  • empty() - Empties the Queue of all items.

Sample Usage

// Load the Queue factory.
var Queues = require('@pxtrick/Queues');

// Create a new Circular Queue object.
var circularQueue = Queues.newCircularQueue();
circularQueue.push( {id:'firstItem'} );
circularQueue.push( {id:'secondItem'} );
circularQueue.push( {id:'thirdItem'} );

circularQueue.next();  // 'firstItem'
circularQueue.next();  // 'secondItem'
circularQueue.next();  // 'thirdItem'
circularQueue.next();  // 'firstItem'
circularQueue.next();  // 'secondItem'