3.0.0 • Published 1 year ago

tinyqueue v3.0.0

Weekly downloads
605,545
License
ISC
Repository
github
Last release
1 year 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-offlinebst-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@rubyquaildesign/quail-artjson-processingjsasyncio-queueskarn-mapkarn-mapbox-glkt-maplibre-gllg-mapbox-glmapbox-glmapbox-gl--custom-stretchmapbox-gl-ahtmapbox-gl-custom-layermapbox-gl-tdtsdmapbox-gl-testmapbox-gl-testingmapbox-gl-tultmapbox-gl_wstdmapbox-gl-encryptedmapbox-gl-epsg4490mapbox-gl-js-with-shapesmapbox-gl-kyemapglvmapmetrics-glmapmetrics-gl-testmaplibre-gl-reduce-functionalitiesmaplibre-gl-tdtsdmaplibre-glmaplibre-gl-ashmapbox-gl-mdorymapbox-gl-mapmagicmapbox-gl-mbtilesmapbox-with-shapesmapbox-gl-htmapbox-gl-hxmapmagic-glmapshapermapshaper-flatbushmapsi-glmartinez-polygon-clippinglabel-lib-canvasleap-nodeldtree-browsermerge-k-sorted-arrays@windycom/maplibre-gl@webdeb/mapbox-gl@xbcx/mapbox-gl@tssu/mapbox-gl@tommy2gis/maplibre-gl@tommy2gis/maplibre-gl-style-spec@tommy2gis/swsk-mapbox-gl@trackasia/trackasia-gl-style-spec@treecg/actor-init-typeahead@vwake_vg/frontend-logger@vitaly.varyvdin/maplibre-gl@xll/mapbox-gl@yongju/maplibre-gl@xt-plugins/mapbox-gl@zityspace/react-annotate@zzes/mapbox-glatumanthonyhull-mapbox-glanother-mapmagic-glarkmap-path-finderarrugatorark-mapaperiameos@goongmaps/goong-js@atomist/automation-client@0xfa11/maplibre-gl@3drobotics/mapbox-gl@hansdo/maplibre-gl@gvol-org/mapbox-gl@aibee/map2d@aibee/map2d-aibee@aibee/map2d-dev@alantgeo/mapbox-gl
3.0.0

1 year ago

2.0.3

6 years ago

2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.2.3

8 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.0

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago