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

Function retrieveRealDataBitmaps

real_data_benchmark_test.go:35–120  ·  view source on GitHub ↗
(datasetName string, optimize bool)

Source from the content-addressed store, hash-verified

33}
34
35func retrieveRealDataBitmaps(datasetName string, optimize bool) ([]*Bitmap, error) {
36 gopath, ok := os.LookupEnv("GOPATH")
37 if !ok {
38 return nil, fmt.Errorf("GOPATH not set. It's required to locate real-roaring-datasets. Set GOPATH or disable BENCH_REAL_DATA")
39 }
40
41 basePath := path.Join(gopath, "src", "github.com", "RoaringBitmap", "real-roaring-datasets")
42
43 if _, err := os.Stat(basePath); os.IsNotExist(err) {
44 return nil, fmt.Errorf("real-roaring-datasets does not exist. Run `go get github.com/RoaringBitmap/real-roaring-datasets`")
45 }
46
47 datasetPath := path.Join(basePath, datasetName+".zip")
48
49 if _, err := os.Stat(datasetPath); os.IsNotExist(err) {
50 return nil, fmt.Errorf("dataset %s does not exist, tried path: %s", datasetName, datasetPath)
51 }
52
53 zipFile, err := zip.OpenReader(datasetPath)
54 if err != nil {
55 return nil, fmt.Errorf("error opening dataset %s zipfile, cause: %v", datasetPath, err)
56 }
57 defer zipFile.Close()
58
59 var largestFileSize uint64
60 for _, f := range zipFile.File {
61 if f.UncompressedSize64 > largestFileSize {
62 largestFileSize = f.UncompressedSize64
63 }
64 }
65
66 bitmaps := make([]*Bitmap, len(zipFile.File))
67 buf := make([]byte, largestFileSize)
68 var bufStep uint64 = 32768 // apparently the largest buffer zip can read
69 for i, f := range zipFile.File {
70 r, err := f.Open()
71 if err != nil {
72 return nil, fmt.Errorf("failed to read bitmap file %s from dataset %s, cause: %v", f.Name, datasetName, err)
73 }
74
75 var totalReadBytes uint64
76
77 for {
78 var endOffset uint64
79 if f.UncompressedSize64 < totalReadBytes+bufStep {
80 endOffset = f.UncompressedSize64
81 } else {
82 endOffset = totalReadBytes + bufStep
83 }
84
85 readBytes, err := r.Read(buf[totalReadBytes:endOffset])
86 totalReadBytes += uint64(readBytes)
87
88 if err == io.EOF {
89 r.Close()
90 break
91 } else if err != nil {
92 r.Close()

Callers 1

Calls 4

AddMethod · 0.95
RunOptimizeMethod · 0.95
NewBitmapFunction · 0.70
ReadMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…