ultra-mega-enumerator
Version:
Ultra Mega Enumerator is a lightweight library designed to enumerate various combinatorial objects.
37 lines • 1.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.NGoodPathEnumeration = void 0;
const AbstractEnumeration_1 = require("./AbstractEnumeration");
const DyckWordEnumeration_1 = require("./DyckWordEnumeration"); // Assuming this is defined somewhere
class NGoodPathEnumeration extends AbstractEnumeration_1.AbstractEnumeration {
constructor(n) {
super();
this.dw = new DyckWordEnumeration_1.DyckWordEnumeration(n);
}
hasMoreElements() {
return this.dw.hasMoreElements();
}
nextElement() {
if (!this.hasMoreElements()) {
throw new Error("No such element");
}
return NGoodPathEnumeration.convertDyckWordToPath(this.dw.nextElement());
}
static convertDyckWordToPath(s) {
let x = 0;
let y = 0;
const n = s.length / 2;
const o = new Array(n);
for (let i = 0; i < s.length; i++) {
if (s.charAt(i) === '(') {
o[x++] = y;
}
else {
y++;
}
}
return o;
}
}
exports.NGoodPathEnumeration = NGoodPathEnumeration;
//# sourceMappingURL=NGoodPathEnumeration.js.map