nocake
javascript Stack Queue PriorityQueue LinkedList
Last updated 3 years ago by andy*() .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install nocake 
SYNC missed versions from official npm registry.

nocake

nocake is a JavaScript collections library including Stack, Queue, PriorityQueue, PromiseQueue and LinkedList data structures.

Examples

import { Stack, Queue, PriorityQueue, PromiseQueue,
  LinkedList, DoublyLinkedList, CircularLinkedList } from 'nocake';

let s = new Stack();
s.push(1);
s.push(2);
s.pop(); //=> 2

let q = new Queue();
q.enqueue(1);
q.enqueue(2);
q.dequeue(); //=> 1

let pq = PriorityQueue.of((a, b) => {
  if (a.priority < b.priority) {
    return 1
  }
  if (a.priority > b.priority) {
    return -1
  }
  return 0
});
// enqueue(element[, priority])
pq.enqueue(1);
pq.enqueue(3);
pq.enqueue(2);
pq.dequeue(); //=> {element: 3, priority: 3}
pq.dequeue(); //=> {element: 2, priority: 2}

const promisequeue = PromiseQueue.of({ concurrency: 1 });

const asyncTask = (time) => () => { return new Promise(resolve => {
  setTimeout(resolve, time)
})};

promisequeue.add(asyncTask(1000), { priority: 1 }).then(() => {
  console.log('async task 1000 Done');
});

promisequeue.addAll([asyncTask(2000), asyncTask(4000)], { priority: 2 }).then(() => {
  console.log('async task 2000/4000 Done');
});

promisequeue.add(asyncTask(3000), { priority: 3 }).then(() => {
  console.log('async task 3000 Done');
});

// async task 1000 Done
// async task 3000 Done
// async task 2000/4000 Done

Installation

npm install --save nocake

Usage

You can import one or multiple collections from nocake:

import { Stack, Queue, PriorityQueue, PromiseQueue,
  LinkedList, DoublyLinkedList, CircularLinkedList } from 'nocake';
// or
const { Stack, Queue, PriorityQueue, PromiseQueue,
  LinkedList, DoublyLinkedList, CircularLinkedList } = require('nocake');

Current Tags

  • 0.7.1                                ...           latest (3 years ago)

12 Versions

  • 0.7.1                                ...           3 years ago
  • 0.7.0                                ...           3 years ago
  • 0.6.1                                ...           3 years ago
  • 0.5.1                                ...           3 years ago
  • 0.4.1                                ...           3 years ago
  • 0.3.1                                ...           3 years ago
  • 0.2.3                                ...           3 years ago
  • 0.2.2                                ...           3 years ago
  • 0.2.1                                ...           3 years ago
  • 0.1.2                                ...           3 years ago
  • 0.1.1                                ...           3 years ago
  • 0.1.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 1
Last Month 0
Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2017 © taobao.org |