diff --git a/README.md b/README.md index d43ebab..66c1209 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ 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. @@ -29,7 +29,7 @@ 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" @@ -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 @@ -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 ! diff --git a/sample/go.mod b/sample/go.mod new file mode 100644 index 0000000..e60d8e6 --- /dev/null +++ b/sample/go.mod @@ -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 +) diff --git a/sample/go.sum b/sample/go.sum new file mode 100644 index 0000000..3566770 --- /dev/null +++ b/sample/go.sum @@ -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= diff --git a/sample/main.go b/sample/main.go new file mode 100644 index 0000000..62d4a25 --- /dev/null +++ b/sample/main.go @@ -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 ! +}