Created
March 9, 2018 19:55
-
-
Save mschoch/45c7c68713bebfc3e96fc9c664662d42 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import ( | |
| "log" | |
| "os" | |
| "testing" | |
| "github.com/RoaringBitmap/roaring" | |
| mmap "github.com/edsrzf/mmap-go" | |
| ) | |
| func TestRoar(t *testing.T) { | |
| os.RemoveAll("/tmp/rf1") | |
| os.RemoveAll("/tmp/rf2") | |
| // create 2 roarings, serialized into files | |
| roaring1 := roaring.New() | |
| roaring1.Add(1) | |
| rf1, err := os.Create("/tmp/rf1") | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| _, err = roaring1.WriteTo(rf1) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| err = rf1.Close() | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| roaring2 := roaring.New() | |
| roaring2.Add(3) | |
| rf2, err := os.Create("/tmp/rf2") | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| _, err = roaring2.WriteTo(rf2) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| err = rf2.Close() | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| // mmap those roarings | |
| rf1, err = os.Open("/tmp/rf1") | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| rf1mmap, err := mmap.Map(rf1, mmap.RDONLY, 0) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| rf2, err = os.Open("/tmp/rf2") | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| rf2mmap, err := mmap.Map(rf2, mmap.RDONLY, 0) | |
| if err != nil { | |
| t.Fatal(err) | |
| } | |
| rv := roaring.New() | |
| another := roaring.New() | |
| another.FromBuffer(rf1mmap) | |
| log.Printf("about to call or, rv: %v with %v", rv, another) | |
| rv.Or(another) | |
| log.Printf("did call or, rv: %v", rv) | |
| another2 := roaring.New() | |
| another2.FromBuffer(rf2mmap) | |
| log.Printf("about to call or, rv: %v with %v", rv, another2) | |
| rv.Or(another2) | |
| log.Printf("did call or, rv: %v", rv) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Outputs: