binomial-heap
Version:
No dependency binomial heap, compatible with typescript, can have custom compare function
29 lines (28 loc) • 929 B
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.debug = exports.treeClimb = exports.readMin = void 0;
exports.readMin = function (merged, compare, getMin) {
var min = merged[0];
var index = 0;
merged.forEach(function (tree, i) {
if (compare(tree.item, min.item) < 0) {
min = tree;
index = i;
}
});
getMin(index);
};
exports.treeClimb = function (start) {
if (start.parent !== null) {
var temp = start.parent.item;
start.parent.item = start.item;
start.item = temp;
exports.treeClimb(start.parent);
}
};
var debugTree = function (tree) {
var acc = tree.item.toString() + ' ';
tree.children.forEach(function (child) { return acc += debugTree(child); });
return acc;
};
exports.debug = function (heap) { return console.log({ min: heap.minimum, heap: heap.items.map(debugTree) }); };
;