UNPKG

binary-decision-diagram

Version:

A library to create, minimize and optimize binary decision diagrams

76 lines 1.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Branches = void 0; exports.ensureNodesNotStrictEqual = ensureNodesNotStrictEqual; /** * represents the branches of a single node */ class Branches { node; deleted = false; data = {}; constructor(node) { this.node = node; } setBranch(which, branchNode) { const previous = this.data[which]; if (previous === branchNode) { return; } // set new branch this.data[which] = branchNode; branchNode.parents.add(this.node); } getKeyOfNode(node) { if (this.getBranch('0') === node) { return '0'; } else if (this.getBranch('1') === node) { return '1'; } else { throw new Error('none matched'); } } getBranch(which) { return this.data[which]; } getBothBranches() { return [ this.getBranch('0'), this.getBranch('1') ]; } hasBranchAsNode(node) { if (this.getBranch('0') === node || this.getBranch('1') === node) { return true; } else { return false; } } hasNodeIdAsBranch(id) { if (this.getBranch('0').id === id || this.getBranch('1').id === id) { return true; } else { return false; } } areBranchesStrictEqual() { return this.data['0'] === this.data['1']; } hasEqualBranches() { return JSON.stringify(this.data['0']) === JSON.stringify(this.data['1']); } } exports.Branches = Branches; function ensureNodesNotStrictEqual(node1, node2) { if (node1 === node2) { throw new Error('cannot have two strict equal branches'); } } //# sourceMappingURL=branches.js.map