Skip to content

Instantly share code, notes, and snippets.

@sundy-li
Created November 3, 2020 02:24
Show Gist options
  • Save sundy-li/8acddd5c3fa97167477732f7d5a06b65 to your computer and use it in GitHub Desktop.
Save sundy-li/8acddd5c3fa97167477732f7d5a06b65 to your computer and use it in GitHub Desktop.
bitmap.go
package main
import (
"fmt"
"io/ioutil"
"math/rand"
"github.com/RoaringBitmap/roaring"
)
func check(e error) {
if e != nil {
panic(e)
}
}
func main() {
r1 := roaring.New()
initsize := 100000000
for i := 1; i <= initsize; i++ {
r1.Add(rand.Uint32())
}
fmt.Printf("%.1f MB ", float32(r1.GetSizeInBytes())/(1024.0*1024))
r1.RunOptimize()
fmt.Printf("%.1f MB ", float32(r1.GetSizeInBytes())/(1024.0*1024))
data, _ := r1.ToBytes()
err := ioutil.WriteFile("test.bin", data, 0644)
check(err)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment