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

epqueue

v0.11.0

Published

Efficient priority queue written in Rust and compiled to WebAssembly

Downloads

8

Readme

:spider_web: Efficient Priority Queue compiled to WebAssembly

Rust - Tests Test exposed JS API Downloads Github stars npm version license MIT

A priority queue library compiled to WebAssembly to be imported in any JavaScript/TypeScript environment with support to Wasm.

The purpose of the library is to provide a efficient implementation and take advantage of the native speed of WebAssembly language. The algorithm was implemented using a Heap data-structure.

To install and import the library, is simple as any other node.js library:

# installation
npm install epqueue

# Importation
const epqueue = require('epqueue');

:children_crossing: Usage example

const {PQueue} = require('epqueue');

// Creating a ascending priority queue
let queue = new PQueue("asc");

// Inserting keys without associated data
queue.insertK(5)
queue.insertK(1)

console.log(`Popping the key with higher priority: ${queue.popK()}`);
// output: Popping the key with higher priority: 1

// Inserting keys with associated data
queue.insertKV(2, "The data associated to key 2");

console.log(`Popping the key/data with higher priority: ${queue.popKV()}`);
// output: Popping the key/data with higher priority: 2,The data associated to key 2

:scroll: API Documentation

The exported methods/objects can be seen below. It follows the typescript d.ts syntax and is available in the file epqueue.d.ts of the builded package.

export class PQueue {
/**
* Construct a new priority queue.
* 
* If the `order` is "asc" then it's a ascending priority queue.
* If the `order` is "desc" then it's a descending priority queue.
* Otherwise, it throws a exception.
* @param {string} order
*/
  constructor(order: string);


/**
* Insert a key in the priority queue.
*
* The method assumes that there is no data associated with the inserted key.
* @param {number} key
*/
  insertK(key: number): void;


/**
* Insert a key in the priority queue. `insertKV` stands for `insert key and value`.
*
* The `value` should be any data associated with the inserted key.
* @param {number} key
* @param {any} value
*/
  insertKV(key: number, value: any): void;


/**
* Pop from the queue the pair key/value with higher priority.
*
* Returns a array which the first element is the key.
* The returned array have the length 2 if the key has inserted with associated data.
* If the key has inserted without any associated data, it returns a array with a single element.
* @returns {Array<any>}
*/
  popKV(): Array<any>;


/**
* Pop from the queue the key with higher priority.
* @returns {number}
*/
  popK(): number;


/**
* Return the key with higher priority without remove it
* @returns {number}
*/
  topK(): number;


/**
* Return the pair key/value with higher priority without remove it
*
* Returns a array which the first element is the key.
* The returned array have the length 2 if the key has inserted with associated data.
* If the key has inserted without any associated data, it returns a array with a single element.
* @returns {Array<any>}
*/
  topKV(): Array<any>;


/**
* Insert a array of keys in the priority queue. This method is roughly equivalent for calling `insert_k` for each element of the array `keys`, but it's more faster. 
*
* This method is more faster than calling `insert_k` for each key, because using this method just only one call to webassembly happens.
* @param {Array<number>} keys
*/
  bulkInsertK(keys: Array<number>): void;

/**
* Insert an array of keys in the priority queue with associated values. The value `values[0]` is associated with the key `keys[0]`, and so on.
* This method is roughly equivalent for calling `insertKV` for each element of the two array `keys` and `values`, but it's more faster. 
*
* Both array must have the same length, otherwise, an error is thrown.
* @param {Array<number>} keys
* @param {Array<any>} values
*/
  bulkInsertKV(keys: Array<number>, values: Array<any>): void;

/**
* Return a array with the keys with highest priority. The returned keys are removed from the Queue.
* 
* The `quantity` is the number of elements to be returned.
* This methods is more faster than calling `pop_k` repeatedly for popping a sequence of keys.
* @param {number} quantity
* @returns {Float64Array}
*/
  bulkPopK(quantity: number): Float64Array;

/**
* Return a array with the the pairs key/value with highest priority. The returned pairs are removed from the Queue.
* 
* Each element of the returned array is like the returned element of `popKV`, so it's a array with two or one element.
* This methods is more faster than calling `popKV` repeatedly for popping a sequence of key/value.
* @param {number} quantity
* @returns {(Array<any>)[]}
*/
  bulkPopKV(quantity: number): (Array<any>)[];

/**
* The number of keys in the queue.
*/
  readonly length: number;
}

:envelope: License

Released under the MIT License. See LICENSE.md for details.