OrCardinality returns the cardinality of the union between two bitmaps, bitmaps are not modified
(x2 *Bitmap)
| 486 | |
| 487 | // OrCardinality returns the cardinality of the union between two bitmaps, bitmaps are not modified |
| 488 | func (rb *Bitmap) OrCardinality(x2 *Bitmap) uint64 { |
| 489 | pos1 := 0 |
| 490 | pos2 := 0 |
| 491 | length1 := rb.highlowcontainer.size() |
| 492 | length2 := x2.highlowcontainer.size() |
| 493 | answer := uint64(0) |
| 494 | main: |
| 495 | for { |
| 496 | if (pos1 < length1) && (pos2 < length2) { |
| 497 | s1 := rb.highlowcontainer.getKeyAtIndex(pos1) |
| 498 | s2 := x2.highlowcontainer.getKeyAtIndex(pos2) |
| 499 | |
| 500 | for { |
| 501 | if s1 < s2 { |
| 502 | answer += rb.highlowcontainer.getContainerAtIndex(pos1).GetCardinality() |
| 503 | pos1++ |
| 504 | if pos1 == length1 { |
| 505 | break main |
| 506 | } |
| 507 | s1 = rb.highlowcontainer.getKeyAtIndex(pos1) |
| 508 | } else if s1 > s2 { |
| 509 | answer += x2.highlowcontainer.getContainerAtIndex(pos2).GetCardinality() |
| 510 | pos2++ |
| 511 | if pos2 == length2 { |
| 512 | break main |
| 513 | } |
| 514 | s2 = x2.highlowcontainer.getKeyAtIndex(pos2) |
| 515 | } else { |
| 516 | // TODO: could be faster if we did not have to materialize the container |
| 517 | answer += roaring.Or(rb.highlowcontainer.getContainerAtIndex(pos1), x2.highlowcontainer.getContainerAtIndex(pos2)).GetCardinality() |
| 518 | pos1++ |
| 519 | pos2++ |
| 520 | if (pos1 == length1) || (pos2 == length2) { |
| 521 | break main |
| 522 | } |
| 523 | s1 = rb.highlowcontainer.getKeyAtIndex(pos1) |
| 524 | s2 = x2.highlowcontainer.getKeyAtIndex(pos2) |
| 525 | } |
| 526 | } |
| 527 | } else { |
| 528 | break |
| 529 | } |
| 530 | } |
| 531 | for ; pos1 < length1; pos1++ { |
| 532 | answer += rb.highlowcontainer.getContainerAtIndex(pos1).GetCardinality() |
| 533 | } |
| 534 | for ; pos2 < length2; pos2++ { |
| 535 | answer += x2.highlowcontainer.getContainerAtIndex(pos2).GetCardinality() |
| 536 | } |
| 537 | return answer |
| 538 | } |
| 539 | |
| 540 | // AndCardinality returns the cardinality of the intersection between two bitmaps, bitmaps are not modified |
| 541 | func (rb *Bitmap) AndCardinality(x2 *Bitmap) uint64 { |