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

queue-adt

v0.1.1

Published

Queue ADT for browser and nodejs

Downloads

3

Readme

queue-adt Build Status

Queue ADT for browser and nodejs

The Queue class represents a first-in-first-out (FIFO) queue of generic items. It supports the usual enqueue and dequeue operations, along with methods for examining the front of the queue, testing if the queue is empty, and iterating through the items in FIFO order.

Install

Download the production version or the development version.

$ npm install --save queue-adt
$ bower install --save queue-adt

Usage

var Queue = require('queue-adt');
var queue = new Queue();

queue.enqueue(10);
queue.first();
queue.isEmpty();
queue.enqueue("foo");
queue.enqueue({hello: "world"});
queue.first().hello; // Outputs "world"
queue.enqueue(function(){ console.log("hello") });
queue.first()(); // Outputs "world"
queue.size();
queue.dequeue();
queue.size();

var itr = queue.iterator;

while(itr.hasNext()) {
  console.log(itr.next());
}

queue.empty();
<script type="text/javascript" src="https://raw.githubusercontent.com/pasangsherpa/queue-adt/master/dist/queue-adt.min.js"></script>
<script type="text/javascript"> 
  var queue = new Queue();

  queue.enqueue(10);
  queue.first();
  queue.isEmpty();
  queue.enqueue("foo");
  queue.enqueue({hello: "world"});
  queue.first().hello; // Outputs "world"
  queue.enqueue(function(){ console.log("hello") });
  queue.first()(); // Outputs "world"
  queue.size();
  queue.dequeue();
  queue.size();

  var itr = queue.iterator;

  while(itr.hasNext()) {
    console.log(itr.next());
  }

  queue.empty();
</script>

Documentation

Queue()

Creates an empty queue with infinite capacity.

Queue(initialCapacity)

Creates an empty queue using the specified capacity.

initialCapacity

Type: int

initialCapacity represents the specified capacity.

Methods

.enqueue(element) throws "Queue is full" error

Adds an element to the rear of the queue and returns the new size of the queue.

element

Type: object

the element to be added to the queue.

.dequeue() throws "Queue is empty" error

Removes an element from the front of the queue and returns the element.

Type: object

the element removed from the front of the queue.

.first() throws "Queue is empty" error

Returns without removing the element at the front of the queue.

Type: object

the element at the front of the queue.

.isEmpty()

Returns true if this queue contains no elements.

Type: boolean

whether or not the queue is empty.

.size()

Returns the number of elements in the queue.

Type: int

the number of element in the queue.

.empty()

Removes all element from the the queue and returns the new size of the queue.

.iterator

Returns an iterator to the queue that iterates through the items in FIFO order.

Type: object

the iterator object of the queue

.iterator.next() throws "No such element" error

Returns the next item in FIFO order.

.iterator.hasNext()

Returns whether the queue has next item in FIFO order.

License

MIT © Pasang Sherpa