And computes the intersection between two bitmaps and stores the result in the current bitmap
(x2 *Bitmap)
| 1365 | |
| 1366 | // And computes the intersection between two bitmaps and stores the result in the current bitmap |
| 1367 | func (rb *Bitmap) And(x2 *Bitmap) { |
| 1368 | pos1 := 0 |
| 1369 | pos2 := 0 |
| 1370 | intersectionsize := 0 |
| 1371 | length1 := rb.highlowcontainer.size() |
| 1372 | length2 := x2.highlowcontainer.size() |
| 1373 | |
| 1374 | main: |
| 1375 | for { |
| 1376 | if pos1 < length1 && pos2 < length2 { |
| 1377 | s1 := rb.highlowcontainer.getKeyAtIndex(pos1) |
| 1378 | s2 := x2.highlowcontainer.getKeyAtIndex(pos2) |
| 1379 | for { |
| 1380 | if s1 == s2 { |
| 1381 | c1 := rb.highlowcontainer.getWritableContainerAtIndex(pos1) |
| 1382 | c2 := x2.highlowcontainer.getContainerAtIndex(pos2) |
| 1383 | diff := c1.iand(c2) |
| 1384 | if !diff.isEmpty() { |
| 1385 | rb.highlowcontainer.replaceKeyAndContainerAtIndex(intersectionsize, s1, diff, false) |
| 1386 | intersectionsize++ |
| 1387 | } |
| 1388 | pos1++ |
| 1389 | pos2++ |
| 1390 | if (pos1 == length1) || (pos2 == length2) { |
| 1391 | break main |
| 1392 | } |
| 1393 | s1 = rb.highlowcontainer.getKeyAtIndex(pos1) |
| 1394 | s2 = x2.highlowcontainer.getKeyAtIndex(pos2) |
| 1395 | } else if s1 < s2 { |
| 1396 | pos1 = rb.highlowcontainer.advanceUntil(s2, pos1) |
| 1397 | if pos1 == length1 { |
| 1398 | break main |
| 1399 | } |
| 1400 | s1 = rb.highlowcontainer.getKeyAtIndex(pos1) |
| 1401 | } else { // s1 > s2 |
| 1402 | pos2 = x2.highlowcontainer.advanceUntil(s1, pos2) |
| 1403 | if pos2 == length2 { |
| 1404 | break main |
| 1405 | } |
| 1406 | s2 = x2.highlowcontainer.getKeyAtIndex(pos2) |
| 1407 | } |
| 1408 | } |
| 1409 | } else { |
| 1410 | break |
| 1411 | } |
| 1412 | } |
| 1413 | rb.highlowcontainer.resize(intersectionsize) |
| 1414 | } |
| 1415 | |
| 1416 | // OrCardinality returns the cardinality of the union between two bitmaps, bitmaps are not modified |
| 1417 | func (rb *Bitmap) OrCardinality(x2 *Bitmap) uint64 { |