GithubHelp home page GithubHelp logo

integer-queue's Introduction

Queue

This is a fixed-size queue that is uses typed arrays to beat the native implementation in terms of speed.

Installation

npm install integer-queue, then require('integer-queue').

Usage

new Queue(size[, type])

Create a new Queue that holds size elements of type type (see typed array views). This defaults to Int32Array.

queue.enqueue(item)

Attempt to enqueue item. If the queue is full, throw a QueueException. If item cannot be represented as an instance of the Queue's type, behaviour following this action is undefined.

queue.dequeue()

Attempt to dequeue the next item. If the queue is empty, throw a QueueException.

Testing, etc.

Run npm test to run the test suite. Run grunt profile to see how this queue performs against a naive solution using native arrays. Notice that the naive solution slows dramatically past 100k elements or so (because of an optimisation trick that Node.js uses for small arrays).

Implementation details

Using an array is a bad idea, because shift re-indexes the array every time and thus a push/shift (or even worse, an unshift/pop) queue runs in linear time with respect to its length.

integer-queue's People

Contributors

bumfo avatar elldritch avatar

Stargazers

 avatar

Watchers

 avatar

Forkers

bumfo

integer-queue's Issues

Incorrect queue fullness detection

poc

let q = new Queue(2);

q.enqueue(1);
q.enqueue(1);
q.dequeue();
q.dequeue();
q.enqueue(1); // Error: Attempted to add to full queue.

fix

if @tail - @head is @length

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.