Last active
June 20, 2021 22:23
-
-
Save linfongi/643681694d027f7afea689d864cdc242 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Heap(n=((n,t)=>n-t)){const t=[];return{push:function(e){t.push(e),function(){let e=t.length-1,o=e-1>>1;for(;0!==e&&n(t[e],t[o])<0;)[t[e],t[o]]=[t[o],t[e]],o=(e=o)-1>>1}()},pop:function(){const o=e(),u=t.pop();t.length>0&&(t[0]=u,function(){let e=0;for(;;){let o=e;for(const u of[2*e+1,2*e+2])u<t.length&&n(t[u],t[o])<0&&(o=u);if(o===e)return;[t[e],t[o]]=[t[o],t[e]],e=o}}());return o},peek:e,size:function(){return t.length}};function e(){return t[0]}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment