MCPcopy Create free account
hub / github.com/Rich-Harris/magic-string / BitSet

Class BitSet

src/BitSet.ts:1–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1export 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}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected