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

Function getRandomSameThreeContainers

runcontainer_test.go:2733–2764  ·  view source on GitHub ↗

generate random contents, then return that same logical content in three different container types

(tr trial)

Source from the content-addressed store, hash-verified

2731// generate random contents, then return that same
2732// logical content in three different container types
2733func getRandomSameThreeContainers(tr trial) (*arrayContainer, *runContainer16, *bitmapContainer) {
2734 ma := make(map[int]bool)
2735
2736 n := tr.n
2737 a := []uint16{}
2738
2739 var samp interval16
2740 if tr.srang != nil {
2741 samp = *tr.srang
2742 } else {
2743 if n-1 > MaxUint16 {
2744 panic(fmt.Errorf("n out of range: %v", n))
2745 }
2746 samp.start = 0
2747 samp.length = uint16(n - 2)
2748 }
2749
2750 draw := int(float64(n) * tr.percentFill)
2751 for i := 0; i < draw; i++ {
2752 r0 := int(samp.start) + rand.Intn(samp.runlen())
2753 a = append(a, uint16(r0))
2754 ma[r0] = true
2755 }
2756
2757 rc := newRunContainer16FromVals(false, a...)
2758
2759 // vs bitmapContainer
2760 bc := newBitmapContainerFromRun(rc)
2761 ac := rc.toArrayContainer()
2762
2763 return ac, rc, bc
2764}

Calls 4

runlenMethod · 0.95
toArrayContainerMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…