| 1 | export class BitSet { |
| 2 | declare bits: number[] |
| 3 | |
| 4 | constructor(arg?: BitSet) { |
| 5 | this.bits = arg instanceof BitSet ? arg.bits.slice() : [] |
| 6 | } |
| 7 | |
| 8 | add(n: number): void { |
| 9 | this.bits[n >> 5] |= 1 << (n & 31) |
| 10 | } |
| 11 | |
| 12 | has(n: number): boolean { |
| 13 | return !!(this.bits[n >> 5] & (1 << (n & 31))) |
| 14 | } |
| 15 | |
| 16 | forEach(fn: (n: number) => void): void { |
| 17 | const bits = this.bits |
| 18 | for (let w = 0; w < bits.length; w++) { |
| 19 | let word = bits[w] |
| 20 | while (word) { |
| 21 | const lowest = word & -word |
| 22 | fn((w << 5) + 31 - Math.clz32(lowest)) |
| 23 | word ^= lowest |
| 24 | } |
| 25 | } |
| 26 | } |
| 27 | } |
nothing calls this directly
no outgoing calls
no test coverage detected