MCPcopy Create free account
hub / github.com/microsoft/SandDance / Heap

Function Heap

docs/app/js/sanddance-app.js:108654–108675  ·  view source on GitHub ↗
(cmp)

Source from the content-addressed store, hash-verified

108652 return this;
108653}
108654function Heap(cmp) {
108655 let nodes = [];
108656 return {
108657 clear: ()=>nodes = [],
108658 size: ()=>nodes.length,
108659 peek: ()=>nodes[0],
108660 push: (x)=>{
108661 nodes.push(x);
108662 return siftdown(nodes, 0, nodes.length - 1, cmp);
108663 },
108664 pop: ()=>{
108665 const last = nodes.pop();
108666 let item;
108667 if (nodes.length) {
108668 item = nodes[0];
108669 nodes[0] = last;
108670 siftup(nodes, 0, cmp);
108671 } else item = last;
108672 return item;
108673 }
108674 };
108675}
108676function siftdown(array, start, idx, cmp) {
108677 let parent, pidx;
108678 const item = array[idx];

Callers 1

DataflowFunction · 0.70

Calls 2

siftdownFunction · 0.70
siftupFunction · 0.70

Tested by

no test coverage detected