-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbitmap.go
More file actions
62 lines (50 loc) · 908 Bytes
/
Copy pathbitmap.go
File metadata and controls
62 lines (50 loc) · 908 Bytes
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package ungo
type Bitmap struct {
data []byte
size uint
}
func NewBitmap(size uint) *Bitmap {
return &Bitmap{
data: make([]byte, size),
size: size,
}
}
func (b *Bitmap) Set(bit uint) {
b.data[bit/8] |= 1 << (bit % 8)
}
func (b *Bitmap) Clear(bit uint) {
b.data[bit/8] &= ^(1 << (bit % 8))
}
func (b *Bitmap) Test(bit uint) bool {
return b.data[bit/8]&(1<<(bit%8)) != 0
}
func (b *Bitmap) Size() uint {
return b.size
}
func (b *Bitmap) Count() uint {
count := uint(0)
for _, v := range b.data {
count += uint(v)
}
return count
}
func (b *Bitmap) Data() []byte {
return b.data
}
func (b *Bitmap) Dump(arr []byte) {
copy(arr, b.data)
}
func (b *Bitmap) Load(arr []byte) {
copy(b.data, arr)
}
func (b *Bitmap) Reset() {
for i := range b.data {
b.data[i] = 0
}
}
func (b *Bitmap) Clone() *Bitmap {
return &Bitmap{
data: append([]byte(nil), b.data...),
size: b.size,
}
}