MCPcopy
hub / github.com/google/gvisor / FirstOne

Method FirstOne

pkg/bitmap/bitmap.go:103–122  ·  view source on GitHub ↗

FirstOne returns the first set bit from the range [start, )

(start uint32)

Source from the content-addressed store, hash-verified

101
102// FirstOne returns the first set bit from the range [start, )
103func (b *Bitmap) FirstOne(start uint32) (bit uint32, err error) {
104 i, nbit := int(start/64), start%64
105 n := len(b.bitBlock)
106 if i >= n {
107 return MaxBitEntryLimit, fmt.Errorf("given start of range exceeds bitmap size")
108 }
109 w := b.bitBlock[i] & (math.MaxUint64 << nbit)
110 for {
111 if w != uint64(0) {
112 r := bits.TrailingZeros64(w)
113 return uint32(r + i*64), nil
114 }
115 i++
116 if i == n {
117 break
118 }
119 w = b.bitBlock[i]
120 }
121 return MaxBitEntryLimit, fmt.Errorf("bitmap has no set bits")
122}
123
124// Maximum return the largest value in the Bitmap.
125func (b *Bitmap) Maximum() uint32 {

Callers 3

SetFlagsForRangeMethod · 0.80
RemoveNextInRangeMethod · 0.80
TestFirstOneFunction · 0.80

Calls 1

ErrorfMethod · 0.65

Tested by 1

TestFirstOneFunction · 0.64