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

Method iandNotArray

bitmapcontainer.go:984–1021  ·  view source on GitHub ↗
(ac *arrayContainer)

Source from the content-addressed store, hash-verified

982}
983
984func (bc *bitmapContainer) iandNotArray(ac *arrayContainer) container {
985 if ac.isEmpty() || bc.isEmpty() {
986 // Nothing to do.
987 return bc
988 }
989
990 // Word by word, we remove the elements in ac from bc. The approach is to build
991 // a mask of the elements to remove, and then apply it to the bitmap.
992 wordIdx := uint16(0)
993 mask := uint64(0)
994 for i, v := range ac.content {
995 if v/64 != wordIdx {
996 // Flush the current word.
997 if i != 0 {
998 // We're removing bits that are set in the mask and in the current word.
999 // To figure out the cardinality change, we count the number of bits that
1000 // are set in the mask and in the current word.
1001 mask &= bc.bitmap[wordIdx]
1002 bc.bitmap[wordIdx] &= ^mask
1003 bc.cardinality -= int(popcount(mask))
1004 }
1005
1006 wordIdx = v / 64
1007 mask = 0
1008 }
1009 mask |= 1 << (v % 64)
1010 }
1011
1012 // Flush the last word.
1013 mask &= bc.bitmap[wordIdx]
1014 bc.bitmap[wordIdx] &= ^mask
1015 bc.cardinality -= int(popcount(mask))
1016
1017 if bc.getCardinality() <= arrayDefaultMaxSize {
1018 return bc.toArrayContainer()
1019 }
1020 return bc
1021}
1022
1023func (bc *bitmapContainer) iandNotRun16(rc *runContainer16) container {
1024 if rc.isEmpty() || bc.isEmpty() {

Callers 1

iandNotMethod · 0.95

Calls 5

isEmptyMethod · 0.95
getCardinalityMethod · 0.95
toArrayContainerMethod · 0.95
popcountFunction · 0.70
isEmptyMethod · 0.65

Tested by

no test coverage detected