reference the java implementation https://github.com/RoaringBitmap/RoaringBitmap/blob/master/src/main/java/org/roaringbitmap/BitmapContainer.java#L875-L892
()
| 1249 | // reference the java implementation |
| 1250 | // https://github.com/RoaringBitmap/RoaringBitmap/blob/master/src/main/java/org/roaringbitmap/BitmapContainer.java#L875-L892 |
| 1251 | func (bc *bitmapContainer) numberOfRuns() int { |
| 1252 | if bc.cardinality == 0 { |
| 1253 | return 0 |
| 1254 | } |
| 1255 | |
| 1256 | var numRuns uint64 |
| 1257 | nextWord := bc.bitmap[0] |
| 1258 | |
| 1259 | for i := 0; i < len(bc.bitmap)-1; i++ { |
| 1260 | word := nextWord |
| 1261 | nextWord = bc.bitmap[i+1] |
| 1262 | numRuns += popcount((^word)&(word<<1)) + ((word >> 63) &^ nextWord) |
| 1263 | } |
| 1264 | |
| 1265 | word := nextWord |
| 1266 | numRuns += popcount((^word) & (word << 1)) |
| 1267 | if (word & 0x8000000000000000) != 0 { |
| 1268 | numRuns++ |
| 1269 | } |
| 1270 | |
| 1271 | return int(numRuns) |
| 1272 | } |
| 1273 | |
| 1274 | // convert to run or array *if needed* |
| 1275 | func (bc *bitmapContainer) toEfficientContainer() container { |
no test coverage detected