Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix typo in README and add sample usage #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ and 54 zeros will be compressed in 38 bits (See enumCode.go for detail).
This achieves not only its information theoretic bound, but also achieves more compression
if bits are clusterd.
rsdic stores information at most 1.3 bit per original bit including its indicies, and compress more if bit vector
is "compresible".
is "compressible".

This Go version is based on the C++ implementation [2].
But this Go version supports PushBack so that it can support dynamic addition.

- [1] "Fast, Small, Simple Rank/Select on Bitmaps", Gonzalo Navarro and Eliana Providel, SEA 2012 [pdf](http://www.dcc.uchile.cl/~gnavarro/ps/sea12.1.pdf)
- [2] C++ version https://code.google.com/p/rsdic/ (the same author)

Usage
Usage (details are in `./sample`)
=====

import "github.com/hillbig/rsdic"
Expand All @@ -51,7 +51,7 @@ Usage
// Select(rank uint64, bit bool) returns the position of (rank+1)-th occurence of bit in B.
oneNum := rsd.OneNum()
for i := uint64(0); i < oneNum; i++ {
fmt.Printf("%d:%d\n", rsd.Select(i, true))
fmt.Printf("%d:%d\n", i, rsd.Select(i, true))
}
// 0:0
// 1:2
Expand All @@ -60,9 +60,9 @@ Usage
rsd.PushBack(false) // You can add anytime

// Use MarshalBinary() and UnmarshalBinary() for serialize/deserialize RSDic.
bytes, err := rsd.MarshalBinary()
newrsd := rsdic.NewRSDic()
err := newrsd.UnmarshalBinary(bytes)
bytes, _ := rsd.MarshalBinary()
newrsd := rsdic.New()
_ = newrsd.UnmarshalBinary(bytes)

// Enjoy !

Expand Down
8 changes: 8 additions & 0 deletions sample/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module sample

go 1.14

require (
github.com/hillbig/rsdic v0.0.0-20150805052524-6158e7a2d824
github.com/ugorji/go v1.1.7 // indirect
)
6 changes: 6 additions & 0 deletions sample/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
github.com/hillbig/rsdic v0.0.0-20150805052524-6158e7a2d824 h1:t71y5fcBE2nktZDXhTmPdZXrdFGBFAiHcOTTk0/+1to=
github.com/hillbig/rsdic v0.0.0-20150805052524-6158e7a2d824/go.mod h1:ivdNV4DsR3UB9xzoIPzw0OipHZf+I7VklGmx0jLkgwo=
github.com/ugorji/go v1.1.7 h1:/68gy2h+1mWMrwZFeD1kQialdSzAb432dtpeJ42ovdo=
github.com/ugorji/go v1.1.7/go.mod h1:kZn38zHttfInRq0xu/PH0az30d+z6vm202qpg1oXVMw=
github.com/ugorji/go/codec v1.1.7 h1:2SvQaVZ1ouYrrKKwoSk2pzd4A9evlKJb9oTL+OaLUSs=
github.com/ugorji/go/codec v1.1.7/go.mod h1:Ax+UKWsSmolVDwsd+7N3ZtXu+yMGCf907BLYF3GoBXY=
41 changes: 41 additions & 0 deletions sample/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"fmt"

"github.com/hillbig/rsdic"
)

func main() {

rsd := rsdic.New()
rsd.PushBack(true)
rsd.PushBack(false)
rsd.PushBack(true)
rsd.PushBack(true)
// rsd = 1011
fmt.Printf("%d %d %d\n", rsd.Num(), rsd.OneNum(), rsd.ZeroNum()) // 4 3 1

// Bit(pos uint64) returns B[pos]
fmt.Printf("%v\n", rsd.Bit(2)) // true

// Rank(pos uint64, bit bool) returns the number of bit's in B[0...pos)
fmt.Printf("%d %d\n", rsd.Rank(2, false), rsd.Rank(4, true)) // 1 3

// Select(rank uint64, bit bool) returns the position of (rank+1)-th occurence of bit in B.
oneNum := rsd.OneNum()
for i := uint64(0); i < oneNum; i++ {
fmt.Printf("%d:%d\n", i, rsd.Select(i, true))
}
// 0:0
// 1:2
// 2:3

rsd.PushBack(false) // You can add anytime

// Use MarshalBinary() and UnmarshalBinary() for serialize/deserialize RSDic.
bytes, _ := rsd.MarshalBinary()
newrsd := rsdic.New()
_ = newrsd.UnmarshalBinary(bytes)
// Enjoy !
}