ultra-mega-enumerator
Version:
Ultra Mega Enumerator is a lightweight library designed to enumerate various combinatorial objects.
49 lines • 1.36 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BitSetEnumeration = void 0;
const BitSet_1 = require("./../objects/BitSet");
const AbstractEnumeration_1 = require("./AbstractEnumeration");
class BitSetEnumeration extends AbstractEnumeration_1.AbstractEnumeration {
/**
* @param n the base
*/
constructor(n) {
super();
if (n < 0) {
throw new Error("Invalid argument: n must be non-negative.");
}
this.current = new BitSet_1.BitSet(n);
this.n = n;
}
hasMoreElements() {
return this.current != undefined;
}
next(b) {
const o = b.copy();
let isLast = true;
for (let i = 0; i < this.n; i++) {
if (!o.get(i)) {
o.set(i, true);
isLast = false;
break;
}
else {
o.set(i, false);
}
}
if (isLast) {
return undefined;
}
return o;
}
nextElement() {
if (this.current == undefined) {
throw Error("No such element");
}
const o = this.current;
this.current = this.next(this.current) || undefined;
return o;
}
}
exports.BitSetEnumeration = BitSetEnumeration;
//# sourceMappingURL=BitSetEnumeration.js.map