示例#1
0
func BenchmarkFibDec(b *testing.B) {
	enc := make([][]byte, 1e5)
	for i := range enc {
		v := uint(rand.Int63())
		fc, lfc := fibencode(v)

		array := bit.NewArray(0)
		for _, f := range fc[:len(fc)-1] {
			array.Add(f, 64)
			lfc -= 64
		}
		array.Add(fc[len(fc)-1], lfc)
		array.Add(0x3, 16)

		enc[i] = byteSliceFromUint64Slice(array.Bits())
	}

	idx := make([]int, b.N)
	for i := range idx {
		idx[i] = rand.Intn(len(enc))
	}

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		fibdecode(enc[idx[i]], 1)
	}
}
示例#2
0
func TestFibEncDec(t *testing.T) {
	array := bit.NewArray(0)

	num := int(1e5)
	values := make([]uint, num)
	for i := range values {
		v := uint(rand.Int63())
		values[i] = v

		fc, lfc := fibencode(v)
		for _, f := range fc[:len(fc)-1] {
			array.Add(f, 64)
			lfc -= 64
		}
		array.Add(fc[len(fc)-1], lfc)
	}
	array.Add(0x3, 16)

	bytes := byteSliceFromUint64Slice(array.Bits())
	result := fibdecode(bytes, num)
	for i, v := range values {
		if !assert.EqualValues(t, v, result[i]) {
			break
		}
	}
}
示例#3
0
文件: sdc.go 项目: robskie/sdc
func (a *Array) init() {
	a.bits = bit.NewArray(0)

	selOpts := &ranksel.Options{Sr: sr, Ss: ss}
	a.selector = ranksel.NewBitVector(selOpts)
	a.selector.Add(1, 1)

	a.initialized = true
}
示例#4
0
文件: vec.go 项目: robskie/fibvec
// Initialize vector
func (v *Vector) init() {
	v.bits = bit.NewArray(0)
	v.ranks = make([]int, 1)
	v.indices = make([]int, 1)

	// Add terminating bits
	v.bits.Add(0x3, 3)

	v.initialized = true
}
示例#5
0
文件: vec.go 项目: robskie/ranksel
// NewBitVector creates a new BitVector.
func NewBitVector(opts *Options) *BitVector {
	if opts == nil {
		opts = NewOptions()
	}

	b := bit.NewArray(0)
	rs := make([]int, 1)
	idx := make([]int, 1)

	return &BitVector{
		bits:    b,
		ranks:   rs,
		indices: idx,
		opts:    opts,
	}
}
示例#6
0
文件: sdc.go 项目: robskie/sdc
// GobDecode populates this array from gob streams.
func (a *Array) GobDecode(data []byte) error {
	buf := bytes.NewReader(data)
	dec := gob.NewDecoder(buf)

	a.bits = bit.NewArray(0)
	a.selector = ranksel.NewBitVector(nil)
	err := checkErr(
		dec.Decode(a.bits),
		dec.Decode(a.selector),
		dec.Decode(&a.length),
		dec.Decode(&a.initialized),
	)

	if err != nil {
		err = fmt.Errorf("sdc: decode failed (%v)", err)
	}

	return err
}
示例#7
0
文件: vec.go 项目: robskie/fibvec
// GobDecode populates this vector from gob streams.
func (v *Vector) GobDecode(data []byte) error {
	buf := bytes.NewReader(data)
	dec := gob.NewDecoder(buf)

	v.bits = bit.NewArray(0)
	err := checkErr(
		dec.Decode(v.bits),
		dec.Decode(&v.ranks),
		dec.Decode(&v.indices),
		dec.Decode(&v.popcount),
		dec.Decode(&v.length),
		dec.Decode(&v.initialized),
	)

	if err != nil {
		err = fmt.Errorf("fibvec: decode failed (%v)", err)
	}

	return err
}
示例#8
0
文件: vec.go 项目: robskie/ranksel
// GobDecode populates this vector from gob streams.
func (v *BitVector) GobDecode(data []byte) error {
	buf := bytes.NewReader(data)
	dec := gob.NewDecoder(buf)

	v.opts = NewOptions()
	v.bits = bit.NewArray(0)
	err := checkErr(
		dec.Decode(v.bits),
		dec.Decode(&v.ranks),
		dec.Decode(&v.indices),
		dec.Decode(&v.popcount),
		dec.Decode(v.opts),
	)

	if err != nil {
		err = fmt.Errorf("ranksel: decode failed (%v)", err)
	}

	return err
}