Skip to content

Commit

Permalink
bug fix: bit map for each bit
Browse files Browse the repository at this point in the history
  • Loading branch information
HDT3213 committed Feb 8, 2023
1 parent fe20c6c commit 85ce687
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion datastruct/bitmap/bitmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,13 @@ func (b *BitMap) ForEachBit(begin int64, end int64, cb Callback) {
}
bitOffset++
offset++
if offset >= end {
break
}
}
byteIndex++
bitOffset = 0
if end > 0 && offset == end {
if end > 0 && offset >= end {
break
}
}
Expand Down
4 changes: 2 additions & 2 deletions datastruct/bitmap/bitmap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func TestForEachBit(t *testing.T) {
}
expectOffset := int64(100)
count := 0
bm.ForEachBit(100, 200, func(offset int64, val byte) bool {
bm.ForEachBit(100, 201, func(offset int64, val byte) bool {
if offset != expectOffset {
t.Error("wrong offset")
}
Expand All @@ -78,7 +78,7 @@ func TestForEachBit(t *testing.T) {
count++
return true
})
if count != 100 {
if count != 101 {
t.Error("wrong count")
}
bm = New()
Expand Down

0 comments on commit 85ce687

Please sign in to comment.