Skip to content

Commit 036d4fd

Browse files
committed
move bitmap to bitarray package
1 parent 4029f9a commit 036d4fd

File tree

3 files changed

+28
-14
lines changed

3 files changed

+28
-14
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*.out
2-
*.test
2+
*.test
3+
.idea

bitmap/bitmap.go renamed to bitarray/bitmap.go

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
// Package bitmap contains bitmaps of length 32 and 64 for tracking bool
2-
// values without the need for arrays or hashing.
3-
package bitmap
1+
package bitarray
42

53
// Bitmap32 tracks 32 bool values within a uint32
64
type Bitmap32 uint32
@@ -20,7 +18,7 @@ func (b Bitmap32) HasBit(pos uint) bool {
2018
return (b & (1 << pos)) != 0
2119
}
2220

23-
// PopCount returns the ammount of bits set to 1 in the Bitmap32
21+
// PopCount returns the amount of bits set to 1 in the Bitmap32
2422
func (b Bitmap32) PopCount() int {
2523
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
2624
b -= (b >> 1) & 0x55555555
@@ -49,7 +47,7 @@ func (b Bitmap64) HasBit(pos uint) bool {
4947
return (b & (1 << pos)) != 0
5048
}
5149

52-
// PopCount returns the ammount of bits set to 1 in the Bitmap64
50+
// PopCount returns the amount of bits set to 1 in the Bitmap64
5351
func (b Bitmap64) PopCount() int {
5452
// http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel
5553
b -= (b >> 1) & 0x5555555555555555

bitmap/bitmap_test.go renamed to bitarray/bitmap_test.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package bitmap
1+
package bitarray
22

33
import (
44
"testing"
55

66
"github.com/stretchr/testify/assert"
77
)
88

9-
func TestPopCount32(t *testing.T) {
9+
func TestBitmap32_PopCount(t *testing.T) {
1010
b := []uint32{
1111
uint32(0x55555555), // 0x55555555 = 01010101 01010101 01010101 01010101
1212
uint32(0x33333333), // 0x33333333 = 00110011 00110011 00110011 00110011
@@ -19,7 +19,7 @@ func TestPopCount32(t *testing.T) {
1919
}
2020
}
2121

22-
func TestPopCount64(t *testing.T) {
22+
func TestBitmap64_PopCount(t *testing.T) {
2323
b := []uint64{
2424
uint64(0x5555555555555555),
2525
uint64(0x3333333333333333),
@@ -32,30 +32,45 @@ func TestPopCount64(t *testing.T) {
3232
}
3333
}
3434

35-
func TestSetBit(t *testing.T) {
35+
func TestBitmap32_SetBit(t *testing.T) {
3636
m := Bitmap32(0)
3737
assert.Equal(t, Bitmap32(0x4), m.SetBit(2))
3838
}
3939

40-
func TestClearBit(t *testing.T) {
40+
func TestBitmap32_ClearBit(t *testing.T) {
4141
m := Bitmap32(0x4)
4242
assert.Equal(t, Bitmap32(0), m.ClearBit(2))
4343
}
4444

45-
func TestHasBit(t *testing.T) {
45+
func TestBitmap32_HasBit(t *testing.T) {
4646
m := Bitmap32(0x55555555)
4747
assert.Equal(t, true, m.HasBit(2))
4848
}
4949

50-
func BenchmarkPopCount32(b *testing.B) {
50+
func TestBitmap64_SetBit(t *testing.T) {
51+
m := Bitmap64(0)
52+
assert.Equal(t, Bitmap64(0x4), m.SetBit(2))
53+
}
54+
55+
func TestBitmap64_ClearBit(t *testing.T) {
56+
m := Bitmap64(0x4)
57+
assert.Equal(t, Bitmap64(0), m.ClearBit(2))
58+
}
59+
60+
func TestBitmap64_HasBit(t *testing.T) {
61+
m := Bitmap64(0x55555555)
62+
assert.Equal(t, true, m.HasBit(2))
63+
}
64+
65+
func BenchmarkBitmap32_PopCount(b *testing.B) {
5166
m := Bitmap32(0x33333333)
5267
b.ResetTimer()
5368
for i := b.N; i > 0; i-- {
5469
m.PopCount()
5570
}
5671
}
5772

58-
func BenchmarkPopCount64(b *testing.B) {
73+
func BenchmarkBitmap64_PopCount(b *testing.B) {
5974
m := Bitmap64(0x3333333333333333)
6075
b.ResetTimer()
6176
for i := b.N; i > 0; i-- {

0 commit comments

Comments
 (0)