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

Method numberOfRuns

arraycontainer.go:1247–1279  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1245}
1246
1247func (ac *arrayContainer) numberOfRuns() (nr int) {
1248 n := len(ac.content)
1249 var runlen uint16
1250 var cur, prev uint16
1251
1252 switch n {
1253 case 0:
1254 return 0
1255 case 1:
1256 return 1
1257 default:
1258 for i := 1; i < n; i++ {
1259 prev = ac.content[i-1]
1260 cur = ac.content[i]
1261
1262 if cur == prev+1 {
1263 runlen++
1264 } else {
1265 if cur < prev {
1266 panic("the fundamental arrayContainer assumption of sorted ac.content was broken")
1267 }
1268 if cur == prev {
1269 panic("the fundamental arrayContainer assumption of deduplicated content was broken")
1270 } else {
1271 nr++
1272 runlen = 0
1273 }
1274 }
1275 }
1276 nr++
1277 }
1278 return
1279}
1280
1281// convert to run or array *if needed*
1282func (ac *arrayContainer) toEfficientContainer() container {

Callers 1

toEfficientContainerMethod · 0.95

Calls

no outgoing calls

Tested by

no test coverage detected