/* COPYRIGHT Esri - https://js.arcgis.com/5.0/LICENSE.txt */
class t{constructor(t){this.comparePriority=t,this._rep=[]}insert(t){this.checkInvariant();const e=this._rep,r=e.length;e.push(t),this.heapifyDown(r),this.checkInvariant()}get length(){return this._rep.length}get(){this.checkInvariant();const t=this._rep;if(0===t.length)return;const e=t[0];return t.length>1?(t[0]=t[t.length-1],t.length-=1,this.heapifyUp(0)):t.length=0,this.checkInvariant(),e}peek(){const t=this._rep;if(0!==t.length)return t[0]}heapifyDown(t){const e=this._rep;let r=t;const n=this.comparePriority;for(;r>0;){const t=this.getParent(r);if(!(n(e[t],e[r])>0))break;this.swap(r,t),r=t}}heapifyUp(t){const r=this._rep;e(0<=t&&t<r.length);const n=this.comparePriority;let i=t;for(;;){if(i>=r.length)break;const t=this.getChild0(i);if(t>=r.length)break;const e=t+1;if(e>=r.length){n(r[t],r[i])<0&&this.swap(i,t);break}{const h=n(r[t],r[e])<0?t:e;if(!(n(r[h],r[i])<0))break;this.swap(i,h),i=h}}}swap(t,e){const r=this._rep,n=r[t];r[t]=r[e],r[e]=n}getParent(t){return Math.trunc((t+1)/2)-1}getChild0(t){return 2*(t+1)-1}checkInvariant(){}}function e(t,e){if(!t)throw console.error("Assertion failed: ",e,", at ",(new Error).stack),new Error("77")}export{t as PriorityQueue};
