• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

osspkg / go-algorithms / 16648427798

31 Jul 2025 12:03PM UTC coverage: 76.074% (-6.2%) from 82.317%
16648427798

Pull #25

markus621
add bitmap + refactoring bloom filter and base62
Pull Request #25: add bitmap + refactoring bloom filter and base62

134 of 207 new or added lines in 3 files covered. (64.73%)

5 existing lines in 1 file now uncovered.

372 of 489 relevant lines covered (76.07%)

30.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

80.65
/structs/bitmap/bitmap.go
1
/*
2
 *  Copyright (c) 2019-2025 Mikhail Knyazhev <markus621@yandex.com>. All rights reserved.
3
 *  Use of this source code is governed by a BSD 3-Clause license that can be found in the LICENSE file.
4
 */
5

6
package bitmap
7

8
import (
9
        "sync"
10
)
11

12
const (
13
        blockSize = 8
14
)
15

16
type Bitmap struct {
17
        data    []byte
18
        size    uint64
19
        max     uint64
20
        mux     sync.RWMutex
21
        lockoff bool
22
}
23

24
type Option func(*Bitmap)
25

NEW
26
func DisableLock() Option {
×
NEW
27
        return func(o *Bitmap) {
×
NEW
28
                o.lockoff = true
×
NEW
29
        }
×
30
}
31

32
func New(maxIndex uint64, opts ...Option) *Bitmap {
1✔
33
        size := maxIndex/blockSize + maxIndex%blockSize
1✔
34

1✔
35
        bm := &Bitmap{
1✔
36
                max:  size * blockSize,
1✔
37
                size: size,
1✔
38
                data: make([]byte, size),
1✔
39
        }
1✔
40

1✔
41
        for _, opt := range opts {
1✔
NEW
42
                opt(bm)
×
NEW
43
        }
×
44

45
        return bm
1✔
46
}
47

48
func (b *Bitmap) Set(index uint64) {
66✔
49
        if index > b.max {
66✔
NEW
50
                return
×
NEW
51
        }
×
52

53
        if !b.lockoff {
132✔
54
                b.mux.Lock()
66✔
55
                defer b.mux.Unlock()
66✔
56
        }
66✔
57

58
        b.data[index%b.size] |= 1 << (index % blockSize)
66✔
59
}
60

61
func (b *Bitmap) Del(index uint64) {
66✔
62
        if index > b.max {
66✔
NEW
63
                return
×
NEW
64
        }
×
65

66
        if !b.lockoff {
132✔
67
                b.mux.Lock()
66✔
68
                defer b.mux.Unlock()
66✔
69
        }
66✔
70

71
        b.data[index%b.size] &^= 1 << (index % blockSize)
66✔
72
}
73

74
func (b *Bitmap) Has(index uint64) bool {
462✔
75
        if index > b.max {
462✔
NEW
76
                return false
×
NEW
77
        }
×
78

79
        if !b.lockoff {
924✔
80
                b.mux.RLock()
462✔
81
                defer b.mux.RUnlock()
462✔
82
        }
462✔
83

84
        return (b.data[index%b.size] & (1 << (index % blockSize))) > 0
462✔
85
}
86

87
func (b *Bitmap) Dump() []byte {
1✔
88
        if !b.lockoff {
2✔
89
                b.mux.RLock()
1✔
90
                defer b.mux.RUnlock()
1✔
91
        }
1✔
92

93
        out := make([]byte, b.size)
1✔
94
        copy(out, b.data)
1✔
95
        return out
1✔
96
}
97

98
func (b *Bitmap) Restore(in []byte) {
2✔
99
        if !b.lockoff {
4✔
100
                b.mux.Lock()
2✔
101
                defer b.mux.Unlock()
2✔
102
        }
2✔
103

104
        b.data = make([]byte, len(in))
2✔
105
        copy(b.data, in)
2✔
106

2✔
107
        b.size = uint64(len(in))
2✔
108
        b.max = b.size * blockSize
2✔
109
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc