File: bitset.go

package info (click to toggle)
golang-github-evanw-esbuild 0.25.10-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,184 kB
  • sloc: javascript: 28,602; makefile: 856; sh: 17
file content (27 lines) | stat: -rw-r--r-- 491 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
package helpers

import "bytes"

type BitSet struct {
	entries []byte
}

func NewBitSet(bitCount uint) BitSet {
	return BitSet{make([]byte, (bitCount+7)/8)}
}

func (bs BitSet) HasBit(bit uint) bool {
	return (bs.entries[bit/8] & (1 << (bit & 7))) != 0
}

func (bs BitSet) SetBit(bit uint) {
	bs.entries[bit/8] |= 1 << (bit & 7)
}

func (bs BitSet) Equals(other BitSet) bool {
	return bytes.Equal(bs.entries, other.entries)
}

func (bs BitSet) String() string {
	return string(bs.entries)
}