And computes the intersection between two bitmaps and stores the result in the current bitmap
(x2 *Bitmap)
| 436 | |
| 437 | // And computes the intersection between two bitmaps and stores the result in the current bitmap |
| 438 | func (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 | |
| 445 | main: |
| 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 |
| 488 | func (rb *Bitmap) OrCardinality(x2 *Bitmap) uint64 { |