quetie
    TypeScript icon, indicating that this package has built-in type declarations

    0.1.0 • Public • Published

    quetie

    Just the cutest and tiniest queue/deque implementation!

    Features

    Install

    $ npm i quetie

    Usage

    import { Queue, Deque } from 'quetie'
    
    const queue = new Queue()
    
    queue.push(1)
    queue.push(2)
    queue.push(3)
    
    console.log(queue.size)
    //=> 3
    
    console.log(queue.get(0))
    console.log(queue.get(1))
    console.log(queue.get(2))
    console.log(queue.get(3))
    console.log(queue.get(-1))
    //=> 1
    //=> 2
    //=> 3
    //=> 1
    //=> 3
    
    console.log([...queue])
    //=> [ 1, 2, 3 ]
    
    console.log(queue.shift())
    console.log(queue.shift())
    console.log(queue.shift())
    console.log(queue.shift())
    //=> 1
    //=> 2
    //=> 3
    //=> undefined
    
    const deque = new Deque()
    
    deque.push(1)
    deque.push(2)
    deque.push(3)
    deque.unshift(0)
    
    console.log(deque.size)
    //=> 4
    
    console.log(deque.get(0))
    console.log(deque.get(1))
    console.log(deque.get(2))
    console.log(deque.get(3))
    console.log(deque.get(-1))
    //=> 0
    //=> 1
    //=> 2
    //=> 3
    //=> 3
    
    console.log([...deque])
    //=> [ 0, 1, 2, 3 ]
    
    console.log(deque.pop())
    console.log(deque.shift())
    console.log(deque.shift())
    console.log(deque.pop())
    console.log(deque.pop())
    //=> 3
    //=> 0
    //=> 1
    //=> 2
    //=> undefined

    See the type definitions for more documentation.

    Benchmarks

    Higher is better!

    Queue

    Random sequence of 1,000,000 push and shift calls:

    native array x 24.16 ops/sec ±1.50% (44 runs sampled)
    quetie x 69.70 ops/sec ±0.31% (72 runs sampled)
    yocto-queue x 65.58 ops/sec ±0.19% (68 runs sampled)
    denque x 63.27 ops/sec ±0.30% (66 runs sampled)
    double-ended-queue x 30.84 ops/sec ±0.42% (55 runs sampled)
    

    100,000 push calls followed by 100,000 shift calls:

    native array x 1.21 ops/sec ±0.52% (8 runs sampled)
    quetie x 196 ops/sec ±3.23% (83 runs sampled)
    yocto-queue x 154 ops/sec ±1.11% (87 runs sampled)
    denque x 177 ops/sec ±1.72% (82 runs sampled)
    double-ended-queue x 132 ops/sec ±2.99% (63 runs sampled)
    

    Deque

    Random sequence of 1,000,000 push, pop, shift, and unshift calls:

    native array x 23.83 ops/sec ±1.60% (44 runs sampled)
    quetie x 65.25 ops/sec ±0.40% (68 runs sampled)
    denque x 62.34 ops/sec ±0.30% (65 runs sampled)
    double-ended-queue x 40.98 ops/sec ±0.36% (55 runs sampled)
    

    Contributing

    Stars are always welcome!

    For bugs and feature requests, please create an issue.

    For pull requests, please read the contributing guidelines.

    License

    Apache 2.0

    This is not an official Google product.

    Install

    npm i quetie

    DownloadsWeekly Downloads

    16

    Version

    0.1.0

    License

    Apache-2.0

    Unpacked Size

    20.4 kB

    Total Files

    6

    Last publish

    Collaborators

    • tomeraberbach