mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Add Reset method to Bitmap.
Useful for fully clearing bitmap efficiently without reallocation. PiperOrigin-RevId: 646125349
This commit is contained in:
committed by
gVisor bot
parent
cd3efc6519
commit
a967130bae
@@ -250,6 +250,14 @@ func (b *Bitmap) FlipRange(begin, end uint32) {
|
||||
}
|
||||
}
|
||||
|
||||
// Reset zeroes the entire bitmap.
|
||||
func (b *Bitmap) Reset() {
|
||||
b.numOnes = 0
|
||||
for i := range b.bitBlock {
|
||||
b.bitBlock[i] = 0
|
||||
}
|
||||
}
|
||||
|
||||
// ForEach calls `f` for each set bit in the range [start, end).
|
||||
//
|
||||
// If f returns false, ForEach stops the iteration.
|
||||
|
||||
@@ -292,6 +292,13 @@ func TestBitmapNumOnes(t *testing.T) {
|
||||
if bitmapOnes != uint32(20) {
|
||||
t.Errorf("After ClearRange, GetNumOnes() returns: %v, wanted: %v", bitmapOnes, 20)
|
||||
}
|
||||
|
||||
// Reset to fully clear bitmap.
|
||||
bitmap.Reset()
|
||||
bitmapOnes = bitmap.GetNumOnes()
|
||||
if bitmapOnes != uint32(0) {
|
||||
t.Errorf("After Reset, GetNumOnes() returns: %v, wanted: %v", bitmapOnes, 0)
|
||||
}
|
||||
}
|
||||
|
||||
type bitmapForEachTestcase struct {
|
||||
|
||||
Reference in New Issue
Block a user