MCPcopy Create free account
hub / github.com/RoaringBitmap/roaring / deleteAt

Method deleteAt

runcontainer.go:1341–1380  ·  view source on GitHub ↗

internal helper functions

(curIndex *int, curPosInIndex *uint16)

Source from the content-addressed store, hash-verified

1339// internal helper functions
1340
1341func (rc *runContainer16) deleteAt(curIndex *int, curPosInIndex *uint16) {
1342 ci := *curIndex
1343 pos := *curPosInIndex
1344
1345 // are we first, last, or in the middle of our interval16?
1346 switch {
1347 case pos == 0:
1348 if int(rc.iv[ci].length) == 0 {
1349 // our interval disappears
1350 rc.iv = append(rc.iv[:ci], rc.iv[ci+1:]...)
1351 // curIndex stays the same, since the delete did
1352 // the advance for us.
1353 *curPosInIndex = 0
1354 } else {
1355 rc.iv[ci].start++ // no longer overflowable
1356 rc.iv[ci].length--
1357 }
1358 case pos == rc.iv[ci].length:
1359 // length
1360 rc.iv[ci].length--
1361 // our interval16 cannot disappear, else we would have been pos == 0, case first above.
1362 *curPosInIndex--
1363 // if we leave *curIndex alone, then Next() will work properly even after the delete.
1364 default:
1365 // middle
1366 // split into two, adding an interval16
1367 new0 := newInterval16Range(rc.iv[ci].start, rc.iv[ci].start+*curPosInIndex-1)
1368
1369 new1start := int(rc.iv[ci].start+*curPosInIndex) + 1
1370 if new1start > int(MaxUint16) {
1371 panic("overflow?!?!")
1372 }
1373 new1 := newInterval16Range(uint16(new1start), rc.iv[ci].last())
1374 tail := append([]interval16{new0, new1}, rc.iv[ci+1:]...)
1375 rc.iv = append(rc.iv[:ci], tail...)
1376 // update curIndex and curPosInIndex
1377 *curIndex++
1378 *curPosInIndex = 0
1379 }
1380}
1381
1382func have4Overlap16(astart, alast, bstart, blast int) bool {
1383 if alast+1 <= bstart {

Callers 1

removeKeyMethod · 0.95

Calls 2

newInterval16RangeFunction · 0.85
lastMethod · 0.80

Tested by

no test coverage detected