ultra-mega-enumerator
Version:
Ultra Mega Enumerator is a lightweight library designed to enumerate various combinatorial objects.
53 lines • 2 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.WeakOrderEnumeration = void 0;
const AbstractEnumeration_1 = require("./AbstractEnumeration");
const CompositionEnumeration_1 = require("./CompositionEnumeration");
const WordPermutationEnumeration_1 = require("./WordPermutationEnumeration");
class WeakOrderEnumeration extends AbstractEnumeration_1.AbstractEnumeration {
constructor(n) {
super();
this.ce = null;
this.me = null;
this.currentBase = [];
this.zerocase = [];
if (n > 0) {
this.ce = new CompositionEnumeration_1.CompositionEnumeration(n);
this.nextBase();
this.me = new WordPermutationEnumeration_1.WordPermutationEnumeration(this.currentBase);
}
}
nextBase() {
if (this.ce === null)
throw new Error("The unexpected has happened.");
const s = this.ce.nextElement().getCompositionAsArray();
this.currentBase = new Array(s.length);
for (let i = 0; i < s.length; i++) {
this.currentBase[i] = s[i];
}
}
hasMoreElements() {
if (this.ce === null || this.me === null) {
return this.zerocase != null;
}
return this.ce.hasMoreElements() || this.me.hasMoreElements();
}
nextElement() {
if (this.ce === null || this.me === null) {
if (this.zerocase == null)
throw new Error("No such element.");
this.zerocase = null;
return [];
}
if (!this.me.hasMoreElements()) {
if (!this.ce.hasMoreElements()) {
throw new Error("No such element");
}
this.nextBase();
this.me = new WordPermutationEnumeration_1.WordPermutationEnumeration(this.currentBase);
}
return this.me.nextElement();
}
}
exports.WeakOrderEnumeration = WeakOrderEnumeration;
//# sourceMappingURL=WeakOrderEnumeration.js.map