All Projects → jviide → Sorted Queue

jviide / Sorted Queue

Licence: mit
A sorted queue, based on an array-backed binary heap

Programming Languages

javascript
184084 projects - #8 most used programming language
typescript
32286 projects

Projects that are alternatives of or similar to Sorted Queue

DEPRECATED-data-structures
A collection of powerful data structures
Stars: ✭ 2,648 (+2496.08%)
Mutual labels:  priority-queue
Data Structures
Go datastructures.
Stars: ✭ 336 (+229.41%)
Mutual labels:  priority-queue
Sidekiq Priority
Prioritize Sidekiq jobs within queues
Stars: ✭ 47 (-53.92%)
Mutual labels:  priority-queue
jheaps
Master repository for the JHeaps project
Stars: ✭ 34 (-66.67%)
Mutual labels:  priority-queue
Mlib
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).
Stars: ✭ 321 (+214.71%)
Mutual labels:  priority-queue
High Speed Priority Queue For C Sharp
A C# priority queue optimized for pathfinding applications
Stars: ✭ 777 (+661.76%)
Mutual labels:  priority-queue
heap-js
Efficient Binary heap (priority queue, binary tree) data structure for JavaScript / TypeScript. Includes JavaScript methods, Python's heapq module methods, and Java's PriorityQueue methods.
Stars: ✭ 66 (-35.29%)
Mutual labels:  priority-queue
Kue
Kue is a priority job queue backed by redis, built for node.js.
Stars: ✭ 9,316 (+9033.33%)
Mutual labels:  priority-queue
Tinyqueue
The smallest and simplest priority queue in JavaScript.
Stars: ✭ 322 (+215.69%)
Mutual labels:  priority-queue
Libgenerics
libgenerics is a minimalistic and generic library for C basic data structures.
Stars: ✭ 42 (-58.82%)
Mutual labels:  priority-queue
concurrent-tasks
A simple task runner which will run all tasks till completion, while maintaining concurrency limits.
Stars: ✭ 27 (-73.53%)
Mutual labels:  priority-queue
Swiftpriorityqueue
A Generic Priority Queue in Pure Swift
Stars: ✭ 314 (+207.84%)
Mutual labels:  priority-queue
Iris
Convenient wrapper library to perform network queries using Retrofit and Android Priority Job Queue (Job Manager)
Stars: ✭ 17 (-83.33%)
Mutual labels:  priority-queue
priority queue
A JavaScript PriorityQueue
Stars: ✭ 28 (-72.55%)
Mutual labels:  priority-queue
Buckets Js
A complete, fully tested and documented data structure library written in pure JavaScript.
Stars: ✭ 1,128 (+1005.88%)
Mutual labels:  priority-queue
priority-queue-dictionary
A Pythonic indexed priority queue
Stars: ✭ 74 (-27.45%)
Mutual labels:  priority-queue
Heapify
The fastest JavaScript priority queue out there. Zero dependencies.
Stars: ✭ 520 (+409.8%)
Mutual labels:  priority-queue
Flatqueue
A very fast and simple JavaScript priority queue
Stars: ✭ 98 (-3.92%)
Mutual labels:  priority-queue
Advancedasynctask
Enhanced AsyncTask library for Android
Stars: ✭ 77 (-24.51%)
Mutual labels:  priority-queue
Coding Ninjas Java Solutions
This will have solutions to all the problems that are included in Coding Ninja's 2020 Java Course. Star the repo if you like it.
Stars: ✭ 32 (-68.63%)
Mutual labels:  priority-queue

sorted-queue npm

A sorted queue, based on an array-backed binary heap.

Installation

$ npm install --save sorted-queue

Usage

import { SortedQueue } from "sorted-queue";

const queue = new SortedQueue();

// `queue.push()` adds a value to the queue and returns an object
// `item` with the `item.value` set to the pushed value.
queue.push(1);        // { value: 1, ... }
queue.push(-1);       // { value: -1, ... }
queue.push(0);        // { value: 0, ... }

// `queue.peek()` returns the item with the smallest value.
queue.peek().value;   // -1

// `queue.pop()` returns the item with the smallest value
// and also removes it from the queue.
queue.pop().value;    // -1
queue.pop().value;    // 0
queue.pop().value;    // 1

// `pop()` and `peek()` return `undefined` when the queue is empty
queue.pop();          // undefined
queue.peek();         // undefined

// Items returned by push() can also be removed using `item.pop()`.
const first = queue.push(0);
const middle = queue.push(1);
const last = queue.push(2);

// `item.pop()` returns `true` if the item existed in the queue, and
// `false` if the item has already been removed previously.
middle.pop();         // true
middle.pop();         // false

// The order is preserved no matter from which position the item got
// removed from.
first.pop();          // true
queue.pop().value;    // 2
queue.pop();          // undefined

// For more complex sortings you can defined a custom comparison function
// (with the same signature as the comparison function Array#sort takes).
const custom = new SortedQueue<{ name: string }>((a, b) => a.name.localeCompare(b.name));
custom.push({ name: "Mallory" });
custom.push({ name: "Alice" });
custom.push({ name: "Bob" });
custom.pop().value;   // { name: "Alice" }
custom.pop().value;   // { name: "Bob" }
custom.pop().value;   // { name: "Mallory" }

License

This library is licensed under the MIT license. See LICENSE.

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].