goroar

package module
v0.0.0-...-4d517f6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 21, 2014 License: Apache-2.0 Imports: 6 Imported by: 0

README

goroar

goroar is an implementation of Roaring Bitmaps in Golang. Roaring bitmaps is a new form of compressed bitmaps, proposed by Daniel Lemire et. al., which often offers better compression and fast access than other compressed bitmap approaches.

Make sure to check Lemire's paper for a detailed explanation and comparison with WAH and Concise.

Usage

Get the library using go get:

go get github.com/fzandona/goroar
Quickstart
package main

import (
    "fmt"

    "github.com/fzandona/goroar"
)

func main() {
    rb1 := goroar.BitmapOf(1, 2, 3, 4, 5)
    rb2 := goroar.BitmapOf(2, 3, 4)
    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)

    // prints 1, 2, 3, 4, 5
    for value := range rb3.Iterator() {
        fmt.Println(value)
    }
}
Documentation

Documentation of the latest code in master is available at godoc.

Compression

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

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:

* 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

Documentation

Overview

goroar is an implementation of Roaring Bitmaps in Golang. Roaring bitmaps is a new form of compressed bitmaps, proposed by Daniel Lemire et. al., which often offers better compression and fast access than other compressed bitmap approaches.

Example (Goroar)

ExampleGoroar demonstrates how to use the goroar library.

package main

import (
	"fmt"

	"github.com/fzandona/goroar"
)

func main() {
	rb1 := goroar.BitmapOf(1, 2, 3, 4, 5)
	rb2 := goroar.BitmapOf(2, 3, 4)
	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)

	// prints 1, 2, 3, 4, 5
	for value := range rb3.Iterator() {
		fmt.Println(value)
	}
}
Output:

Example (Large)

ExampleLarge demonstrates how to use the goroar library.

package main

import (
	"fmt"

	"github.com/fzandona/goroar"
)

func main() {
	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()
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type RoaringBitmap

type RoaringBitmap struct {
	// contains filtered or unexported fields
}

func BitmapOf

func BitmapOf(values ...uint32) *RoaringBitmap

BitmapOf generates a new bitmap with the specified values set to true. The provided values don't have to be in sorted order, but it may be preferable to sort them from a performance point of view.

func New

func New() *RoaringBitmap

New creates a new RoaringBitmap

func (*RoaringBitmap) Add

func (rb *RoaringBitmap) Add(x uint32)

Add adds a uint32 value to the RoaringBitmap

func (*RoaringBitmap) And

func (rb *RoaringBitmap) And(other *RoaringBitmap)

And computes the bitwise AND operation. The receiving RoaringBitmap is modified - the input one is not.

func (*RoaringBitmap) AndNot

func (rb *RoaringBitmap) AndNot(other *RoaringBitmap)

AndNot computes the bitwise andNot operation (difference) The receiving RoaringBitmap is modified - the input one is not.

func (*RoaringBitmap) Cardinality

func (rb *RoaringBitmap) Cardinality() int

Cardinality returns the number of distinct integers (uint32) in the bitmap.

func (*RoaringBitmap) Clone

func (rb *RoaringBitmap) Clone() *RoaringBitmap

Clone returns a copy of the original RoaringBitmap

func (*RoaringBitmap) Contains

func (rb *RoaringBitmap) Contains(i uint32) bool

Contains checks whether the value in included, which is equivalent to checking if the corresponding bit is set (get in BitSet class).

func (*RoaringBitmap) Iterator

func (rb *RoaringBitmap) Iterator() <-chan uint32

Iterator returns an iterator over the RoaringBitmap which can be used with "for range".

func (*RoaringBitmap) Or

func (rb *RoaringBitmap) Or(other *RoaringBitmap)

Or computes the bitwise OR operation. The receiving RoaringBitmap is modified - the input one is not.

func (*RoaringBitmap) SizeInBytes

func (rb *RoaringBitmap) SizeInBytes() int

func (*RoaringBitmap) Stats

func (rb *RoaringBitmap) Stats()

Stats prints statistics about the Roaring Bitmap's internals.

func (*RoaringBitmap) String

func (rb *RoaringBitmap) String() string

func (*RoaringBitmap) Xor

func (rb *RoaringBitmap) Xor(other *RoaringBitmap)

Xor computes the bitwise XOR operation. The receiving RoaringBitmap is modified - the input one is not.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL