コード例 #1
0
ファイル: fastpfor.go プロジェクト: jmptrader/encoding
func New() encoding.Integer {
	f := &FastPFOR{
		pageSize:      DefaultPageSize,
		byteContainer: bytebuffer.NewByteBuffer(3*DefaultPageSize/DefaultBlockSize + DefaultPageSize),
		dataPointers:  make([]int32, 33),
		freqs:         make([]int32, 33),
	}

	for i := 1; i < 33; i++ {
		f.dataToBePacked[i] = make([]int32, DefaultPageSize/32*4)
	}

	return f
}
コード例 #2
0
ファイル: variablebyte.go プロジェクト: jmptrader/encoding
func (this *VariableByte) Compress(in []int32, inpos *cursor.Cursor, inlength int, out []int32, outpos *cursor.Cursor) error {
	if inlength == 0 {
		return errors.New("variablebyte/Compress: inlength = 0. No work done.")
	}

	//fmt.Printf("variablebyte/Compress: after inlength = %d\n", inlength)

	buf := bytebuffer.NewByteBuffer(inlength * 8)
	initoffset := int32(0)

	tmpinpos := inpos.Get()
	for _, v := range in[tmpinpos : tmpinpos+inlength] {
		val := uint32(v - initoffset)
		initoffset = v

		for val >= 0x80 {
			buf.Put(byte(val) | 0x80)
			val >>= 7
		}
		buf.Put(byte(val))
	}

	for buf.Position()%4 != 0 {
		//fmt.Printf("variablebyte/Compress: putting 128\n")
		buf.Put(128)
	}

	length := buf.Position()
	buf.Flip()
	ibuf := buf.AsInt32Buffer()
	//fmt.Printf("variablebyte/Compress: l = %d, outpos = %d, ibuf = %v, buf = %v\n", length/4, outpos.Get(), ibuf, buf)
	err := ibuf.GetInt32s(out, outpos.Get(), length/4)
	if err != nil {
		//fmt.Printf("variablebyte/Compress: error with GetUint32s - %v\n", err)
		return err
	}
	outpos.Add(length / 4)
	inpos.Add(inlength)
	//fmt.Printf("variablebyte/Compress: out = %v\n", out)

	return nil
}