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

Function TestRleRandomUnion16

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

Source from the content-addressed store, hash-verified

538}
539
540func TestRleRandomUnion16(t *testing.T) {
541 t.Run("RunContainer.union of two RunContainers should return their union, and this should hold over randomized container content when compared to union done with hash maps", func(t *testing.T) {
542 seed := int64(42)
543 rand.Seed(seed)
544
545 trials := []trial{
546 {n: 100, percentFill: .80, ntrial: 10},
547 {n: 1000, percentFill: .20, ntrial: 20},
548 {n: 10000, percentFill: .01, ntrial: 10},
549 {n: 1000, percentFill: .99, ntrial: 10, percentDelete: .04},
550 }
551
552 tester := func(tr trial) {
553 for j := 0; j < tr.ntrial; j++ {
554 ma := make(map[int]bool)
555 mb := make(map[int]bool)
556
557 n := tr.n
558 a := []uint16{}
559 b := []uint16{}
560
561 draw := int(float64(n) * tr.percentFill)
562 numDel := int(float64(n) * tr.percentDelete)
563 for i := 0; i < draw; i++ {
564 r0 := rand.Intn(n)
565 a = append(a, uint16(r0))
566 ma[r0] = true
567
568 r1 := rand.Intn(n)
569 b = append(b, uint16(r1))
570 mb[r1] = true
571 }
572
573 // hash version of union:
574 hashu := make(map[int]bool)
575 for k := range ma {
576 hashu[k] = true
577 }
578 for k := range mb {
579 hashu[k] = true
580 }
581
582 // showHash("hashu", hashu)
583
584 // RunContainer's Union
585 arle := newRunContainer16()
586 for i := range a {
587 arle.Add(a[i])
588 }
589 brle := newRunContainer16()
590 brle.set(false, b...)
591
592 union := arle.union(brle)
593 un := union.AsSlice()
594 slices.Sort(un)
595
596 for kk, v := range un {
597 _ = kk

Callers

nothing calls this directly

Calls 8

newRunContainer16Function · 0.85
setMethod · 0.80
unionMethod · 0.80
AsSliceMethod · 0.80
removeKeyMethod · 0.80
containsMethod · 0.65
getCardinalityMethod · 0.65
AddMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…