New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

queue-adt

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

queue-adt

Queue ADT for browser and nodejs

latest
Source
npmnpm
Version
0.1.1
Version published
Maintainers
1
Created
Source

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

Keywords

queue

FAQs

Package last updated on 04 Aug 2014

Did you know?

Socket

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