1
var Bitset = function (size) {2
//this.bits = new Array(size).fill(0);3
//this.bitsOp = new Array(size).fill(1);6
for (let i = 0; i < size; i++) this.set0.add(i);13
Bitset.prototype.fix = function (idx) {15
//this.bitsOp[idx] = 0;16
if (this.set0.has(idx)) {18
this.set0.delete(idx);26
Bitset.prototype.unfix = function (idx) {28
//this.bitsOp[idx] = 1;29
if (this.set1.has(idx)) {31
this.set1.delete(idx);38
Bitset.prototype.flip = function () {39
//this.bits = this.bits.map(x=>(x)?0:1);40
//this.bits.forEach(x=>x=(x)?0:1);41
[this.set0, this.set1] = [this.set1, this.set0];47
Bitset.prototype.all = function () {48
//return (this.bits.filter(x=>x).length == this.bits.length)49
//return !this.bits.includes(0);50
//for (let i = 0; i<this.bits.length; i++)51
//if (this.bits[i] === 0) return false;53
return this.set0.size === 0;59
Bitset.prototype.one = function () {60
//return this.bits.filter(x=>x).length>061
//return this.bits.includes(1);62
//for (let i = 0; i<this.bits.length; i++)63
//if (this.bits[i] === 1) return true;65
return this.set1.size > 0;71
Bitset.prototype.count = function () {72
//return this.bits.filter(x=>x).length73
//return this.bits.reduce((sum, cur)=>sum+cur);74
return this.set1.size;80
Bitset.prototype.toString = function () {81
//return this.bits.join('');82
let set = new Array(this.set0.size + this.set1.size);83
for (let i = 0; i < set.length; i++) {84
set[i] = this.set0.has(i) ? 0 : 1;