3.0.0 • Published 11 months ago

tinyqueue v3.0.0

Weekly downloads
605,545
License
ISC
Repository
github
Last release
11 months ago

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/tinyqueue@2.0.0/tinyqueue.min.js"></script>

Thanks

Inspired by js-priority-queue by Adam Hooper.

@simosol/mapbox-gl-js-offline@atomist/automation-clientbst-map-glgeojson-path-finder-junctions@modular/dmnc-core@mapcreator/mapbox-gl@infinitebrahmanuniverse/nolb-tinyq@everything-registry/sub-chunk-2950@langge-data/mapbox-gltask-farmsweepline-intersectionssweepline-simplifytemporibusadipiscitest-map-azsftwrwinamp2-jsvwake_jswebampx-mapbox-glswsk-mapboxglswift-sharethinknetmapsvnmapvizzuality-mapbox-glvicapow-mapbox-glvietmap-glvietmaps-gl@dra2020/baseclient@dra2020/baseserver@dra2020/poly@curio/mapbox-gl@rubyquaildesign/quail-artjson-processingjsasyncio-queueskarn-mapkarn-mapbox-glkt-maplibre-gl@openmapvn/maplibre-glswift-share-testsprottysprotty-xudehuatrackasia-gltouchlay-path-finderutils-decorators@americana/maplibre-gl@appearhere/mapbox-gl@ark-org/map@autoxing/mapbox-gl@alantgeo/mapbox-gl@bcherny/mapbox-gl@aibee/map2d@aibee/map2d-dev@bewithjonam/mapbox-gl@carto/mapbox-gl@cczbby/mapbox-gl@cczbby/maplibre-gl@cgcs2000/mapbox-gl@3drobotics/mapbox-gl@0xfa11/maplibre-gl@derhuerst/flow-of-computations@dfw810/mapbox-gl@datavis-tech/polylabelygh-creatorxyd-mapbox-glts-growing-glyphsts-geojson-path-finderxtal-gl@felix5/mapbox-webgl2@dtcv/cities@gvol-org/mapbox-gl@hansdo/maplibre-gl@hdelva/termennetwerk_client@goongmaps/goong-js@eturnity/eturnity_maths@geops/maplibre-gl@geomatico/mapbox-gl@globalfishingwatch/mapbox-gl@globalfishingwatch/maplibre-gl@krisdages/mapbox-gl@koordinates/maplibre-gl@itsjoekent/geokdbush@liquid-js/palette@luminati-io/geokdbush@luqh_mapbox/mapbox-gl@murrayw123/geojsonpathfinderamended@maps-gl/maps-gl@mapbox/polylabel@maptalks/vector-packer@maptalks/vt@mapcat/mapbox-gl@mapgis/mapbox-gl@maplibre/maplibre-gl-style-spec@emuanalytics/maplibre-gl@mapbox/mapbox-gl-style-spec@jingsam/mapbox-gl@ivelander/mapbox-gl@heotaein/concaveman@inelo/maplibre-gl@kantas/vector-js@ogix/mapbox-gl@rczobor/maplibre-gl
3.0.0

11 months ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

7 years ago

1.2.3

8 years ago

1.2.2

8 years ago

1.2.1

8 years ago

1.2.0

8 years ago

1.1.0

9 years ago

1.0.1

10 years ago

1.0.0

10 years ago