Bits = class {
constructor(n = 4) {
this.values = new Uint8Array(n);
}
get(i) {
const byte = i >> 3;
const bit = i % 8;
return (this.values[byte] >> bit) & 1;
}
set(i, value) {
const byte = i >> 3;
if (1 + byte > this.values.length) {
const buf = new Uint8Array(
Math.max(1 + byte, 2 * this.values.length)
);
buf.set(this.values);
this.values = buf;
}
const bit = i % 8;
if (value) this.values[byte] |= 1 << bit;
else this.values[byte] &= ~(1 << bit);
return this;
}
}