Skip to content

dwillmer/phosphor-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

phosphor-queue

Build Status Coverage Status

A generic FIFO queue data structure.

API Docs

Package Install

Prerequisites

npm install --save phosphor-queue

Source Build

Prerequisites

git clone https://github.com/phosphorjs/phosphor-queue.git
cd phosphor-queue
npm install

Rebuild

npm run clean
npm run build

Run Tests

Follow the source build instructions first.

npm test

Build Docs

Follow the source build instructions first.

npm run docs

Navigate to docs/index.html.

Supported Runtimes

The runtime versions which are currently known to work are listed below. Earlier versions may also work, but come with no guarantees.

  • Node 0.12.7+
  • IE 11+
  • Firefox 32+
  • Chrome 38+

Bundle for the Browser

Follow the package install instructions first.

npm install --save-dev browserify browserify-css
browserify -g browserify-css myapp.js -o mybundle.js

Usage Examples

Note: This module is fully compatible with Node/Babel/ES6/ES5. Simply omit the type declarations when using a language other than TypeScript.

import { Queue } from 'phosphor-queue';


var q = new Queue<number>([0, 1, 2, 3]);

q.front;  // 0
q.back;   // 3
q.size;   // 4
q.empty;  // false

q.pop();  // 0
q.pop();  // 1
q.pop();  // 2
q.pop();  // 3
q.pop();  // undefined
q.front;  // undefined
q.back;   // undefined
q.size;   // 0
q.empty;  // true

q.push(42);
q.push(43);
q.push(44);
q.push(44);
q.push(45);

q.toArray();  // [42, 43, 44, 44, 45]

q.remove(42);     // true
q.remove(19);     // false
q.removeAll(44);  // 2
q.removeAll(19);  // 0
q.toArray();      // [43, 45]

q.clear();
q.size;     // 0
q.empty;    // true

q.push(42);
q.push(43);
q.push(44);
q.push(45);

q.some(v => v < 40);  // false
q.some(v => v > 44);  // true

q.every(v => v > 40);  // true
q.every(v => v > 44);  // false

q.filter(v => v < 40);  // []
q.filter(v => v > 44);  // [45]

q.map(v => v * 2);  // [84, 86, 88, 90]

q.forEach((v, i) => {
  console.log(v, i);
});

var index = q.forEach((v, i) => {
  if (v === 43) return i;
});

index;  // 1

About

A generic FIFO queue data structure.

Resources

License

Stars

Watchers

Forks

Packages

No packages published