Skip to content

Commit

Permalink
Readme updates
Browse files Browse the repository at this point in the history
  • Loading branch information
fzandona committed Jul 18, 2014
1 parent 588f570 commit c67879f
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
38 changes: 37 additions & 1 deletion README.md
Expand Up @@ -25,14 +25,15 @@ import (
func main() {
rb1 := goroar.BitmapOf(1, 2, 3, 4, 5)
rb2 := goroar.BitmapOf(2, 3, 4)
rb3 := goroar.BitmapOf(1)
rb3 := goroar.New()

fmt.Println("Cardinality: ", rb1.Cardinality())

fmt.Println("Contains 3? ", rb1.Contains(3))

rb1.And(rb2)

rb3.Add(1)
rb3.Add(5)

rb3.Or(rb1)
Expand All @@ -48,10 +49,45 @@ func main() {

Documentation of the latest code in master is available at [godoc](http://godoc.org/github.com/fzandona/goroar).

Compression
-----------

`RoaringBitmap.Stats()` will print some bitmap stats, mostly for debugging purposes, but it also gives an idea of the bitmap's compression rate.

```go
func Example_stats() {
rb1 := goroar.New()
rb2 := goroar.New()

for i := 0; i < 1000000; i += 2 {
rb1.Add(uint32(i))
rb2.Add(uint32(i + 1))
}

rb1.Or(rb2)
rb1.Stats()
}
```

The code above outputs:

```text
* Roaring Bitmap Stats *
Cardinality: 1000000
Size uncompressed: 4000000 bytes
Size compressed: 131532 bytes
Number of containers: 16
0 ArrayContainers
16 BitmapContainers
Average entries per ArrayContainer: --
Max entries per ArrayContainer: --
```

TODO
----

* Immutable bitwise operations
* Flip, clone, clear operations
* Serialization
* More idiomatic Go
* Test re-factoring & coverage
3 changes: 2 additions & 1 deletion example_goroar_test.go
Expand Up @@ -10,14 +10,15 @@ import (
func Example_goroar() {
rb1 := goroar.BitmapOf(1, 2, 3, 4, 5)
rb2 := goroar.BitmapOf(2, 3, 4)
rb3 := goroar.BitmapOf(1)
rb3 := goroar.New()

fmt.Println("Cardinality: ", rb1.Cardinality())

fmt.Println("Contains 3? ", rb1.Contains(3))

rb1.And(rb2)

rb3.Add(1)
rb3.Add(5)

rb3.Or(rb1)
Expand Down
23 changes: 23 additions & 0 deletions example_large_test.go
@@ -0,0 +1,23 @@
package goroar_test

import (
"fmt"

"github.com/fzandona/goroar"
)

// ExampleLarge demonstrates how to use the goroar library.
func Example_large() {
rb1 := goroar.New()
rb2 := goroar.New()

for i := 0; i < 1000000; i += 2 {
rb1.Add(uint32(i))
rb2.Add(uint32(i + 1))
}
fmt.Println(rb1.Cardinality(), rb2.Cardinality())

rb1.Or(rb2)

rb1.Stats()
}

0 comments on commit c67879f

Please sign in to comment.