diff options
Diffstat (limited to 'pkg/bitmap')
-rw-r--r-- | pkg/bitmap/bitmap.go | 4 | ||||
-rw-r--r-- | pkg/bitmap/bitmap_test.go | 14 |
2 files changed, 9 insertions, 9 deletions
diff --git a/pkg/bitmap/bitmap.go b/pkg/bitmap/bitmap.go index 803b7b3c7..12d2fc2b8 100644 --- a/pkg/bitmap/bitmap.go +++ b/pkg/bitmap/bitmap.go @@ -32,8 +32,8 @@ type Bitmap struct { bitBlock []uint64 } -// BitmapWithSize create a new empty Bitmap. -func BitmapWithSize(size uint32) Bitmap { +// New create a new empty Bitmap. +func New(size uint32) Bitmap { b := Bitmap{} bSize := (size + 63) / 64 b.bitBlock = make([]uint64, bSize) diff --git a/pkg/bitmap/bitmap_test.go b/pkg/bitmap/bitmap_test.go index 37f068438..76ebd779f 100644 --- a/pkg/bitmap/bitmap_test.go +++ b/pkg/bitmap/bitmap_test.go @@ -42,7 +42,7 @@ func generateFilledSlice(min, max, length int) []uint32 { // generateFilledBitmap generates a Bitmap filled with fillNum of numbers, // and returns the slice and bitmap. func generateFilledBitmap(min, max, fillNum int) ([]uint32, Bitmap) { - bitmap := BitmapWithSize(uint32(max)) + bitmap := New(uint32(max)) randSlice := generateFilledSlice(min, max, fillNum) for i := 0; i < fillNum; i++ { bitmap.Add(randSlice[i]) @@ -64,8 +64,8 @@ func TestNewBitmap(t *testing.T) { for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - if bitmap := BitmapWithSize(uint32(tt.size)); len(bitmap.bitBlock) != tt.expectSize { - t.Errorf("BitmapWithSize created bitmap with %v, bitBlock size: %d, wanted: %d", tt.name, len(bitmap.bitBlock), tt.expectSize) + if bitmap := New(uint32(tt.size)); len(bitmap.bitBlock) != tt.expectSize { + t.Errorf("New created bitmap with %v, bitBlock size: %d, wanted: %d", tt.name, len(bitmap.bitBlock), tt.expectSize) } }) } @@ -87,7 +87,7 @@ func TestAdd(t *testing.T) { for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - bitmap := BitmapWithSize(uint32(tt.bitmapSize)) + bitmap := New(uint32(tt.bitmapSize)) bitmap.Add(uint32(tt.addNum)) bitmapSlice := bitmap.ToSlice() if bitmapSlice[0] != uint32(tt.addNum) { @@ -98,7 +98,7 @@ func TestAdd(t *testing.T) { } func TestRemove(t *testing.T) { - bitmap := BitmapWithSize(uint32(1024)) + bitmap := New(uint32(1024)) firstSlice := generateFilledSlice(0, 511, 50) secondSlice := generateFilledSlice(512, 1024, 50) for i := 0; i < 50; i++ { @@ -176,7 +176,7 @@ func TestClearRange(t *testing.T) { for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T) { - bitmap := BitmapWithSize(uint32(tt.bitmapSize)) + bitmap := New(uint32(tt.bitmapSize)) bitmap.FlipRange(uint32(0), uint32(tt.bitmapSize)) bitmap.ClearRange(uint32(tt.clearRangeMin), uint32(tt.clearRangeMax+1)) clearedBitmapSlice := bitmap.ToSlice() @@ -295,7 +295,7 @@ func TestBitmapNumOnes(t *testing.T) { } func TestFirstZero(t *testing.T) { - bitmap := BitmapWithSize(uint32(1000)) + bitmap := New(uint32(1000)) bitmap.FlipRange(200, 400) for i, j := range map[uint32]uint32{0: 0, 201: 400, 200: 400, 199: 199, 400: 400, 10000: math.MaxInt32} { v := bitmap.FirstZero(i) |