npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

diqueue

v1.1.4

Published

A performant updatable priority queue which can pop AND shift.

Downloads

15

Readme

Diqueue

A performant updatable priority queue which can pop AND shift.


Install

$ npm install --save diqueue

Usage

var DiQueue = require('diqueue');

// An empty priority queue
var q = new DiQueue();

q.push(88);
q.push(12);
q.push(23);

q.pop(); // returns 12
q.shift(); // returns 88

// Initialized with data
var qData = new DiQueue([88, 12, 23, 45, 56]);

qData.length; // returns 5
qData.pop(); // returns 12
qData.length; // returns 4
qData.shift(); // returns 88
qData.length; // returns 3
qData.peekPop(); // returns 23
qData.length; // returns 3 (unchanged)
qData.peekShift(); // returns 56
qData.length; // returns 3 (unchanged)

// Initialized with custom comparator
var qComp = new DiQueue([88, 12, 23, 45, 56], (a, b) => {
  return a < b ? a : b;
});

qComp.pop(); // returns 88
qComp.shift(); // returns 12

// Initialized with custom objects
var qObj = new DiQueue([{ name: 'A', lag: 54 }, { name: 'B', lag: 22 }, { name: 'C', lag: 37 }], (a, b) => {
  return a.lag > b.lag ? a : b;
});

qObj.pop() // returns object { name: 'B', lag: 22 }
qObj.shift() // returns object { name: 'A', lag: 54 }

// Initialized an updatable priority queue with a custom key
var qObj2 = new DiQueue([{ name: 'A', lag: 54 }, { name: 'B', lag: 22 }, { name: 'C', lag: 37 },{ name: 'D', lag: 15 }], (a, b) => {
  return a.lag > b.lag ? a : b;
}, 'name');

qObj2.update('A', { name: 'A', lag: 12 });
qObj2.remove('D');

qObj2.pop(); // returns object { name: 'A', lag: 12 }
qObj2.pop(); // returns object { name: 'B', lag: 22 }
qObj2.pop(); // returns object { name: 'C', lag: 37 }

API

constructor(data, compareFn, identityKey)


data

  • Optional
  • Type: Array
  • Default: []

The array of items to insert into the priority queue.

compareFn

  • Optional
  • Type: Function
  • Default: (a, b) => { return a > b ? a : b; }

A comparator function to order the elements in the queue.

identityKey

  • Optional
  • Type: String
  • Default: id

For an updatable queue, the key which is used to identify the object to update.

push(data)


data

  • Required
  • Type: Object

The item to insert into the priority queue.

remove(idValue)


idValue

  • Required
  • Type: Any

The value used to match the object, which will be removed.

update(idValue, updatedItem)


idValue

  • Required
  • Type: Any

The value used to match the object, which will be updated.

updatedItem

  • Required
  • Type: Object

The new item which will replace the previous item that matched the given idValue.

License

MIT © 2017, Muaz Siddiqui

Inspired by:

js-priority-queue by Adam Hooper

tinyqueue by Vladimir Agafonkin

updatable-priority-queue by Benjamin Becquet