@cromarmot/algo
Version:
Algorithms library with controllable time complexity.
43 lines (42 loc) • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.CompManager = void 0;
class CompManager {
constructor() {
this.zone = new Map();
this.ff = {};
}
static createCompManager() {
return new CompManager();
}
reg(fnName, complex, fn) {
var _a;
if (!this.zone.has(fnName)) {
this.zone.set(fnName, new Map());
}
(_a = this.zone.get(fnName)) === null || _a === void 0 ? void 0 : _a.set(complex, fn);
if (!this.ff[fnName]) {
this.ff[fnName] = {};
}
this.ff[fnName][complex] = fn;
}
unreg(fnName, complex) {
var _a;
if (!this.zone.has(fnName)) {
return;
}
(_a = this.zone.get(fnName)) === null || _a === void 0 ? void 0 : _a.delete(complex);
this.ff[fnName][complex] = undefined;
}
f(fnName, complex, ...args) {
var _a, _b;
if (!this.zone.has(fnName)) {
throw new Error(`${fnName} Not found.`);
}
if (!((_a = this.zone.get(fnName)) === null || _a === void 0 ? void 0 : _a.has(complex))) {
throw new Error('Not Implemented.');
}
return ((_b = this.zone.get(fnName)) === null || _b === void 0 ? void 0 : _b.get(complex))(...args);
}
}
exports.CompManager = CompManager;