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

Method And

roaring64/roaring64.go:438–485  ·  view source on GitHub ↗

And computes the intersection between two bitmaps and stores the result in the current bitmap

(x2 *Bitmap)

Source from the content-addressed store, hash-verified

436
437// And computes the intersection between two bitmaps and stores the result in the current bitmap
438func (rb *Bitmap) And(x2 *Bitmap) {
439 pos1 := 0
440 pos2 := 0
441 intersectionsize := 0
442 length1 := rb.highlowcontainer.size()
443 length2 := x2.highlowcontainer.size()
444
445main:
446 for {
447 if pos1 < length1 && pos2 < length2 {
448 s1 := rb.highlowcontainer.getKeyAtIndex(pos1)
449 s2 := x2.highlowcontainer.getKeyAtIndex(pos2)
450 for {
451 if s1 == s2 {
452 c1 := rb.highlowcontainer.getWritableContainerAtIndex(pos1)
453 c2 := x2.highlowcontainer.getContainerAtIndex(pos2)
454 c1.And(c2)
455 if !c1.IsEmpty() {
456 rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, c1, false)
457 intersectionsize++
458 }
459 pos1++
460 pos2++
461 if (pos1 == length1) || (pos2 == length2) {
462 break main
463 }
464 s1 = rb.highlowcontainer.getKeyAtIndex(pos1)
465 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
466 } else if s1 < s2 {
467 pos1 = rb.highlowcontainer.advanceUntil(s2, pos1)
468 if pos1 == length1 {
469 break main
470 }
471 s1 = rb.highlowcontainer.getKeyAtIndex(pos1)
472 } else { // s1 > s2
473 pos2 = x2.highlowcontainer.advanceUntil(s1, pos2)
474 if pos2 == length2 {
475 break main
476 }
477 s2 = x2.highlowcontainer.getKeyAtIndex(pos2)
478 }
479 }
480 } else {
481 break
482 }
483 }
484 rb.highlowcontainer.resize(intersectionsize)
485}
486
487// OrCardinality returns the cardinality of the union between two bitmaps, bitmaps are not modified
488func (rb *Bitmap) OrCardinality(x2 *Bitmap) uint64 {

Callers 14

TestBitmapCOWFunction · 0.95
TestFlipBigACOWFunction · 0.95
TestBitmapFunction · 0.95
TestFlipBigAFunction · 0.95
AndFunction · 0.45
TestBitmapExtraCOWFunction · 0.45
rTestCOWFunction · 0.45
minOrMaxMethod · 0.45
RetainMethod · 0.45
NewBSIRetainSetMethod · 0.45
TestBitmapExtraFunction · 0.45

Calls 8

sizeMethod · 0.45
getKeyAtIndexMethod · 0.45
getContainerAtIndexMethod · 0.45
IsEmptyMethod · 0.45
advanceUntilMethod · 0.45
resizeMethod · 0.45

Tested by 8

TestBitmapCOWFunction · 0.76
TestFlipBigACOWFunction · 0.76
TestBitmapFunction · 0.76
TestFlipBigAFunction · 0.76
TestBitmapExtraCOWFunction · 0.36
rTestCOWFunction · 0.36
TestBitmapExtraFunction · 0.36
rTestFunction · 0.36