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

Function TestExample2_roaring061

example_roaring_test.go:77–126  ·  view source on GitHub ↗

Example_roaring demonstrates how to use the roaring library with run containers.

(t *testing.T)

Source from the content-addressed store, hash-verified

75
76// Example_roaring demonstrates how to use the roaring library with run containers.
77func TestExample2_roaring061(t *testing.T) {
78
79 r1 := New()
80 for i := uint32(100); i < 1000; i++ {
81 r1.Add(i)
82 }
83 if !r1.Contains(500) {
84 t.Errorf("should contain 500")
85 }
86 rb2 := r1.Clone()
87 // compute how many bits there are:
88 cardinality := r1.GetCardinality()
89
90 // if your bitmaps have long runs, you can compress them by calling
91 // run_optimize
92 size := r1.GetSizeInBytes()
93 r1.RunOptimize()
94 if cardinality != r1.GetCardinality() {
95 t.Errorf("RunOptimize should not change cardinality.")
96 }
97 compactSize := r1.GetSizeInBytes()
98 if compactSize >= size {
99 t.Errorf("Run optimized size should be smaller.")
100 }
101 if !r1.Equals(rb2) {
102 t.Errorf("RunOptimize should not affect equality.")
103 }
104 fmt.Print("size before run optimize: ", size, " bytes, and after: ", compactSize, " bytes.\n")
105 rb3 := New()
106 rb3.AddRange(1, 10000000)
107 r1.Or(rb3)
108 if !r1.Equals(rb3) {
109 t.Errorf("union with large run should give back contained set")
110 }
111 rb1 := r1.Clone()
112 rb1.AndNot(rb3)
113 if !rb1.IsEmpty() {
114 t.Errorf("And not with large should clear...")
115 }
116 for i := uint32(0); i < 10000; i += 3 {
117 rb1.Add(i)
118 }
119 rb1.AndNot(rb3)
120 rb1card := rb1.GetCardinality()
121 if rb1card != 1 {
122 //rb1.RunOptimize()
123 //fmt.Printf("\n rb1 = %s\n", rb1)
124 t.Errorf("Only the value 0 should survive the andNot; rb1card = %v", rb1card)
125 }
126}

Callers

nothing calls this directly

Calls 12

NewFunction · 0.70
AddMethod · 0.45
ContainsMethod · 0.45
CloneMethod · 0.45
GetCardinalityMethod · 0.45
GetSizeInBytesMethod · 0.45
RunOptimizeMethod · 0.45
EqualsMethod · 0.45
AddRangeMethod · 0.45
OrMethod · 0.45
AndNotMethod · 0.45
IsEmptyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…