-func mmapTorrentData(metaInfo *metainfo.MetaInfo, location string) (mms mmap_span.MMapSpan, err error) {
- defer func() {
- if err != nil {
- mms.Close()
- mms = nil
- }
- }()
- for _, miFile := range metaInfo.Files {
- fileName := filepath.Join(append([]string{location, metaInfo.Name}, miFile.Path...)...)
- err = os.MkdirAll(filepath.Dir(fileName), 0777)
- if err != nil {
- return
- }
- var file *os.File
- file, err = os.OpenFile(fileName, os.O_CREATE|os.O_RDWR, 0666)
- if err != nil {
- return
- }
- func() {
- defer file.Close()
- var fi os.FileInfo
- fi, err = file.Stat()
- if err != nil {
- return
- }
- if fi.Size() < miFile.Length {
- err = file.Truncate(miFile.Length)
- if err != nil {
- return
- }
- }
- var mMap gommap.MMap
- mMap, err = gommap.MapRegion(file.Fd(), 0, miFile.Length, gommap.PROT_READ|gommap.PROT_WRITE, gommap.MAP_SHARED)
- if err != nil {
- return
- }
- if int64(len(mMap)) != miFile.Length {
- panic("mmap has wrong length")
- }
- mms = append(mms, mMap)
- }()
- if err != nil {
- return
+func boolSliceToBitmap(slice []bool) (rb roaring.Bitmap) {
+ for i, b := range slice {
+ if b {
+ rb.AddInt(i)