MCPcopy
hub / github.com/RoaringBitmap/roaring / CheckedAdd

Method CheckedAdd

roaring.go:1188–1202  ·  view source on GitHub ↗

CheckedAdd adds the integer x to the bitmap and return true if it was added (false if the integer was already present)

(x uint32)

Source from the content-addressed store, hash-verified

1186
1187// CheckedAdd adds the integer x to the bitmap and return true if it was added (false if the integer was already present)
1188func (rb *Bitmap) CheckedAdd(x uint32) bool {
1189 // TODO: add unit tests for this method
1190 hb := highbits(x)
1191 i := rb.highlowcontainer.getIndex(hb)
1192 if i >= 0 {
1193 C := rb.highlowcontainer.getWritableContainerAtIndex(i)
1194 oldcard := C.getCardinality()
1195 C = C.iaddReturnMinimized(lowbits(x))
1196 rb.highlowcontainer.setContainerAtIndex(i, C)
1197 return C.getCardinality() > oldcard
1198 }
1199 newac := newArrayContainer()
1200 rb.highlowcontainer.insertNewKeyValueAt(-i-1, hb, newac.iaddReturnMinimized(lowbits(x)))
1201 return true
1202}
1203
1204// AddInt adds the integer x to the bitmap (convenience method: the parameter is casted to uint32 and we call Add)
1205func (rb *Bitmap) AddInt(x int) {

Callers

nothing calls this directly

Calls 9

newArrayContainerFunction · 0.85
highbitsFunction · 0.70
lowbitsFunction · 0.70
getCardinalityMethod · 0.65
iaddReturnMinimizedMethod · 0.65
getIndexMethod · 0.45
setContainerAtIndexMethod · 0.45
insertNewKeyValueAtMethod · 0.45

Tested by

no test coverage detected