MCPcopy
hub / github.com/RoaringBitmap/roaring / TestRleRandomIntersection16

Function TestRleRandomIntersection16

runcontainer_test.go:457–538  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

455}
456
457func TestRleRandomIntersection16(t *testing.T) {
458 t.Run("RunContainer.intersect of two RunContainers should return their intersection, and this should hold over randomized container content when compared to intersection done with hash maps", func(t *testing.T) {
459 seed := int64(42)
460 rand.Seed(seed)
461
462 trials := []trial{
463 {n: 100, percentFill: .80, ntrial: 10},
464 {n: 1000, percentFill: .20, ntrial: 20},
465 {n: 10000, percentFill: .01, ntrial: 10},
466 {n: 1000, percentFill: .99, ntrial: 10},
467 }
468
469 tester := func(tr trial) {
470 for j := 0; j < tr.ntrial; j++ {
471 ma := make(map[int]bool)
472 mb := make(map[int]bool)
473
474 n := tr.n
475 a := []uint16{}
476 b := []uint16{}
477
478 var first, second int
479
480 draw := int(float64(n) * tr.percentFill)
481 for i := 0; i < draw; i++ {
482 r0 := rand.Intn(n)
483 a = append(a, uint16(r0))
484 ma[r0] = true
485 if i == 0 {
486 first = r0
487 second = r0 + 1
488 a = append(a, uint16(second))
489 ma[second] = true
490 }
491
492 r1 := rand.Intn(n)
493 b = append(b, uint16(r1))
494 mb[r1] = true
495 }
496
497 // print a; very likely it has dups
498 slices.Sort(a)
499 stringA := ""
500 for i := range a {
501 stringA += fmt.Sprintf("%v, ", a[i])
502 }
503
504 // hash version of intersect:
505 hashi := make(map[int]bool)
506 for k := range ma {
507 if mb[k] {
508 hashi[k] = true
509 }
510 }
511
512 // RunContainer's Intersect
513 brle := newRunContainer16FromVals(false, b...)
514

Callers

nothing calls this directly

Calls 7

newArrayContainerRangeFunction · 0.85
setMethod · 0.80
intersectMethod · 0.80
containsMethod · 0.65
getCardinalityMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…