All Projects → mourner → Tinyqueue

mourner / Tinyqueue

Licence: isc
The smallest and simplest priority queue in JavaScript.

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Tinyqueue

Swiftpriorityqueue
A Generic Priority Queue in Pure Swift
Stars: ✭ 314 (-2.48%)
Mutual labels:  data-structure, priority-queue
Bplustree
A minimal but extreme fast B+ tree indexing structure demo for billions of key-value storage
Stars: ✭ 1,598 (+396.27%)
Mutual labels:  algorithm, data-structure
Tastylib
C++ implementations of data structures, algorithms, and system designs.
Stars: ✭ 101 (-68.63%)
Mutual labels:  algorithm, data-structure
Mytinystl
Achieve a tiny STL in C++11
Stars: ✭ 4,813 (+1394.72%)
Mutual labels:  algorithm, data-structure
Data structures and algorithms in python
📖 Worked Solutions of "Data Structures & Algorithms in Python", written by Michael T. Goodrich, Roberto Tamassia and Michael H. Goldwasser. ✏️
Stars: ✭ 147 (-54.35%)
Mutual labels:  algorithm, data-structure
Usaco
General Resources for Competitive Programming
Stars: ✭ 1,152 (+257.76%)
Mutual labels:  algorithm, data-structure
Algorithm
The challenges for algorithm contests, and summary the implementation.
Stars: ✭ 115 (-64.29%)
Mutual labels:  algorithm, data-structure
Algorithm
Algorithm is a library of tools that is used to create intelligent applications.
Stars: ✭ 787 (+144.41%)
Mutual labels:  algorithm, data-structure
Skiplist
skip list with rank, code less than z_set in redis
Stars: ✭ 136 (-57.76%)
Mutual labels:  algorithm, data-structure
Binarytree
Python Library for Studying Binary Trees
Stars: ✭ 1,694 (+426.09%)
Mutual labels:  algorithm, data-structure
Data Structure And Algorithms
A complete and efficient guide for Data Structure and Algorithms.
Stars: ✭ 48 (-85.09%)
Mutual labels:  algorithm, data-structure
Leetcode
High-quality LeetCode solutions
Stars: ✭ 178 (-44.72%)
Mutual labels:  algorithm, data-structure
Awesome Competitive Programming
💎 A curated list of awesome Competitive Programming, Algorithm and Data Structure resources
Stars: ✭ 9,119 (+2731.99%)
Mutual labels:  algorithm, data-structure
Blog
Life is a moment 📔
Stars: ✭ 1,236 (+283.85%)
Mutual labels:  algorithm, data-structure
Algorithm Visualizer
🎆Interactive Online Platform that Visualizes Algorithms from Code
Stars: ✭ 35,995 (+11078.57%)
Mutual labels:  algorithm, data-structure
Algorithm templates
algorithm templates and leetcode examples in Python3, you can learn many python tricks too.
Stars: ✭ 107 (-66.77%)
Mutual labels:  algorithm, data-structure
Lintcode
📘 C++11 Solutions of All 289 LintCode Problems (No More Updates)
Stars: ✭ 570 (+77.02%)
Mutual labels:  algorithm, data-structure
Book on python algorithms and data structure
🪐 Book on Python, Algorithms, and Data Structures. 🪐
Stars: ✭ 604 (+87.58%)
Mutual labels:  algorithm, data-structure
Apachecn Algo Zh
ApacheCN 数据结构与算法译文集
Stars: ✭ 10,498 (+3160.25%)
Mutual labels:  algorithm, data-structure
Leetcode Solutions
🏋️ Python / Modern C++ Solutions of All 2111 LeetCode Problems (Weekly Update)
Stars: ✭ 2,787 (+765.53%)
Mutual labels:  algorithm, data-structure

tinyqueue

The smallest and simplest binary heap priority queue in JavaScript.

// create an empty priority queue
var queue = new TinyQueue();

// add some items
queue.push(7);
queue.push(5);
queue.push(10);

// remove the top item
var top = queue.pop(); // returns 5

// return the top item (without removal)
top = queue.peek(); // returns 7

// get queue length
queue.length; // returns 2

// create a priority queue from an existing array (modifies the array)
queue = new TinyQueue([7, 5, 10]);

// pass a custom item comparator as a second argument
queue = new TinyQueue([{value: 5}, {value: 7}], function (a, b) {
	return a.value - b.value;
});

// turn a queue into a sorted array
var array = [];
while (queue.length) array.push(queue.pop());

For a faster number-based queue, see flatqueue.

Install

Install using NPM (npm install tinyqueue) or Yarn (yarn add tinyqueue), then:

// import as an ES module
import TinyQueue from 'tinyqueue';

// or require in Node / Browserify
const TinyQueue = require('tinyqueue');

Or use a browser build directly:

<script src="https://unpkg.com/[email protected]/tinyqueue.min.js"></script>

Thanks

Inspired by js-priority-queue by Adam Hooper.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].