@js-sdsl/priority-queue
Version:
javascript standard data structure library which benchmark against C++ STL
9 lines (8 loc) • 3.07 kB
JavaScript
/*!
* @js-sdsl/priority-queue v4.4.0
* https://github.com/js-sdsl/js-sdsl
* (c) 2021-present ZLY201 <zilongyao1366@gmail.com>
* MIT license
*/
!function(t,o){"object"==typeof exports&&"undefined"!=typeof module?o(exports):"function"==typeof define&&define.amd?define(["exports"],o):o((t="undefined"!=typeof globalThis?globalThis:t||self).sdsl={})}(this,function(t){"use strict";var r=function(t,o){return(r=Object.setPrototypeOf||({__proto__:[]}instanceof Array?function(t,o){t.__proto__=o}:function(t,o){for(var i in o)Object.prototype.hasOwnProperty.call(o,i)&&(t[i]=o[i])}))(t,o)};function o(t,o){if("function"!=typeof o&&null!==o)throw new TypeError("Class extends value "+String(o)+" is not a constructor or null");function i(){this.constructor=t}r(t,o),t.prototype=null===o?Object.create(o):(i.prototype=o.prototype,new i)}function s(t,o){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var r,n,e=i.call(t),u=[];try{for(;(void 0===o||0<o--)&&!(r=e.next()).done;)u.push(r.value)}catch(t){n={error:t}}finally{try{r&&!r.done&&(i=e.return)&&i.call(e)}finally{if(n)throw n.error}}return u}function h(t,o,i){if(i||2===arguments.length)for(var r,n=0,e=o.length;n<e;n++)!r&&n in o||((r=r||Array.prototype.slice.call(o,0,n))[n]=o[n]);return t.concat(r||Array.prototype.slice.call(o))}Object.defineProperty(e.prototype,"length",{get:function(){return this.t},enumerable:!1,configurable:!0}),e.prototype.size=function(){return this.t},e.prototype.empty=function(){return 0===this.t};var i,n=e;function e(){this.t=0}function u(){return null!==i&&i.apply(this,arguments)||this}o(u,i=n);o(f,p=n),f.prototype.h=function(t){for(var o=this.u[t];0<t;){var i=t-1>>1,r=this.u[i];if(this.i(r,o)<=0)break;this.u[t]=r,t=i}this.u[t]=o},f.prototype.o=function(t,o){for(var i=this.u[t];t<o;){var r=t<<1|1,n=r+1,e=this.u[r];if(n<this.t&&0<this.i(e,this.u[n])&&(e=this.u[r=n]),0<=this.i(e,i))break;this.u[t]=e,t=r}this.u[t]=i},f.prototype.clear=function(){this.t=0,this.u.length=0},f.prototype.push=function(t){this.u.push(t),this.h(this.t),this.t+=1},f.prototype.pop=function(){var t,o;if(0!==this.t)return t=this.u[0],o=this.u.pop(),--this.t,this.t&&(this.u[0]=o,this.o(0,this.t>>1)),t},f.prototype.top=function(){return this.u[0]},f.prototype.find=function(t){return 0<=this.u.indexOf(t)},f.prototype.remove=function(t){t=this.u.indexOf(t);return!(t<0||(0===t?this.pop():t===this.t-1?(this.u.pop(),--this.t):(this.u.splice(t,1,this.u.pop()),--this.t,this.h(t),this.o(t,this.t>>1)),0))},f.prototype.updateItem=function(t){t=this.u.indexOf(t);return!(t<0||(this.h(t),this.o(t,this.t>>1),0))},f.prototype.toArray=function(){return h([],s(this.u),!1)};var p,n=f;function f(t,o,i){void 0===t&&(t=[]),void 0===o&&(o=function(t,o){return o<t?-1:t<o?1:0}),void 0===i&&(i=!0);for(var r,n=p.call(this)||this,e=(n.i=o,Array.isArray(t)?n.u=i?h([],s(t),!1):t:(n.u=[],r=n,t.forEach(function(t){r.u.push(t)})),n.t=n.u.length,n.t>>1),u=n.t-1>>1;0<=u;--u)n.o(u,e);return n}t.PriorityQueue=n,Object.defineProperty(t,"l",{value:!0})});
//# sourceMappingURL=priority-queue.min.js.map