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

Method unionCardinality

runcontainer.go:483–593  ·  view source on GitHub ↗

unionCardinality returns the cardinality of the merger of two runContainer16s, the union of rc and b.

(b *runContainer16)

Source from the content-addressed store, hash-verified

481
482// unionCardinality returns the cardinality of the merger of two runContainer16s, the union of rc and b.
483func (rc *runContainer16) unionCardinality(b *runContainer16) uint {
484 // rc is also known as 'a' here, but golint insisted we
485 // call it rc for consistency with the rest of the methods.
486 answer := uint(0)
487
488 alim := len(rc.iv)
489 blim := len(b.iv)
490
491 var na int // next from a
492 var nb int // next from b
493
494 // merged holds the current merge output, which might
495 // get additional merges before being appended to m.
496 var merged interval16
497 var mergedUsed bool // is merged being used at the moment?
498
499 var cura interval16 // currently considering this interval16 from a
500 var curb interval16 // currently considering this interval16 from b
501
502 pass := 0
503 for na < alim && nb < blim {
504 pass++
505 cura = rc.iv[na]
506 curb = b.iv[nb]
507
508 if mergedUsed {
509 mergedUpdated := false
510 if canMerge16(cura, merged) {
511 merged = mergeInterval16s(cura, merged)
512 na = rc.indexOfIntervalAtOrAfter(int(merged.last())+1, na+1)
513 mergedUpdated = true
514 }
515 if canMerge16(curb, merged) {
516 merged = mergeInterval16s(curb, merged)
517 nb = b.indexOfIntervalAtOrAfter(int(merged.last())+1, nb+1)
518 mergedUpdated = true
519 }
520 if !mergedUpdated {
521 // we know that merged is disjoint from cura and curb
522 // m = append(m, merged)
523 answer += uint(merged.last()) - uint(merged.start) + 1
524 mergedUsed = false
525 }
526 continue
527
528 } else {
529 // !mergedUsed
530 if !canMerge16(cura, curb) {
531 if cura.start < curb.start {
532 answer += uint(cura.last()) - uint(cura.start) + 1
533 // m = append(m, cura)
534 na++
535 } else {
536 answer += uint(curb.last()) - uint(curb.start) + 1
537 // m = append(m, curb)
538 nb++
539 }
540 } else {

Callers 2

orCardinalityMethod · 0.95

Calls 4

lastMethod · 0.95
canMerge16Function · 0.85
mergeInterval16sFunction · 0.85

Tested by 1