示例#1
0
文件: pack.go 项目: zhuharev/intarr
func uncompress(arr []int32) ([]int32, error) {
	newinpos := cursor.New()
	newoutpos := cursor.New()

	recov := make([]int32, 10000)

	codec := bp32.New()
	e := codec.Uncompress(arr, newinpos, len(arr)-1, recov, newoutpos)
	l := 0
	for i, v := range recov[:newoutpos.Get()] {
		if v != 0 {
			l = i
		}
	}
	return recov[:l+1], e
}
示例#2
0
文件: pack.go 项目: zhuharev/intarr
func compress(in []int32) (arr []int32, e error) {
	l := len(in)
	if len(in)%128 != 0 {
		l = l + (128 - len(in)%128)
	}

	arr = make([]int32, l)
	copy(arr, in)

	compdata := make([]int32, 2*l)
	inpos := cursor.New()
	outpos := cursor.New()
	codec := bp32.New()
	e = codec.Compress(arr, inpos, l, compdata, outpos)
	if e != nil {
		return nil, e
	}

	return compdata[:outpos.Get()+1], e
}