Example #1
0
func (this *BP32) Compress(in []int32, inpos *cursor.Cursor, inlength int, out []int32, outpos *cursor.Cursor) error {

	inlength = encoding.FloorBy(inlength, DefaultBlockSize)

	if inlength == 0 {
		return errors.New("BP32/Compress: block size less than 128. No work done.")
	}

	out[outpos.Get()] = int32(inlength)
	outpos.Increment()

	tmpoutpos := outpos.Get()
	s := inpos.Get()
	finalinpos := s + inlength

	for ; s < finalinpos; s += DefaultBlockSize {
		mbits1 := encoding.MaxBits(in[s : s+32])
		mbits2 := encoding.MaxBits(in[s+32 : s+2*32])
		mbits3 := encoding.MaxBits(in[s+2*32 : s+3*32])
		mbits4 := encoding.MaxBits(in[s+3*32 : s+4*32])

		out[tmpoutpos] = (mbits1 << 24) | (mbits2 << 16) | (mbits3 << 8) | mbits4
		tmpoutpos += 1
		bitpacking.FastPackWithoutMask(in, s, out, tmpoutpos, int(mbits1))
		tmpoutpos += int(mbits1)
		bitpacking.FastPackWithoutMask(in, s+32, out, tmpoutpos, int(mbits2))
		tmpoutpos += int(mbits2)
		bitpacking.FastPackWithoutMask(in, s+2*32, out, tmpoutpos, int(mbits3))
		tmpoutpos += int(mbits3)
		bitpacking.FastPackWithoutMask(in, s+3*32, out, tmpoutpos, int(mbits4))
		tmpoutpos += int(mbits4)
	}

	inpos.Add(inlength)
	outpos.Set(tmpoutpos)

	return nil
}
Example #2
0
func (this *BP32) Compress(in []int32, inpos *cursor.Cursor, inlength int, out []int32, outpos *cursor.Cursor) error {
	//log.Printf("zigzag_bp32/Compress: before inlength = %d\n", inlength)

	inlength = encoding.FloorBy(inlength, DefaultBlockSize)

	if inlength == 0 {
		return errors.New("zigzag_bp32/Compress: block size less than 128. No work done.")
	}

	//log.Printf("zigzag_bp32/Compress: after inlength = %d, len(in) = %d\n", inlength, len(in))

	out[outpos.Get()] = int32(inlength)
	outpos.Increment()

	tmpoutpos := outpos.Get()
	s := inpos.Get()
	finalinpos := s + inlength
	delta := make([]int32, DefaultBlockSize)

	for ; s < finalinpos; s += DefaultBlockSize {
		encoding.ZigZagDelta(in[s:s+DefaultBlockSize], delta)
		//log.Printf("zigzag_bp32/Compress: in = %v\n", in[s:s+DefaultBlockSize])
		//log.Printf("zigzag_bp32/Compress: delta = %v\n", delta)

		mbits1 := encoding.MaxBits(delta[0:32])
		mbits2 := encoding.MaxBits(delta[32:64])
		mbits3 := encoding.MaxBits(delta[64:96])
		mbits4 := encoding.MaxBits(delta[96:128])

		//log.Printf("zigzag_bp32/Compress: tmpoutpos = %d, s = %d\n", tmpoutpos, s)

		out[tmpoutpos] = (mbits1 << 24) | (mbits2 << 16) | (mbits3 << 8) | mbits4
		tmpoutpos += 1

		//log.Printf("zigzag_bp32/Compress: mbits1 = %d, mbits2 = %d, mbits3 = %d, mbits4 = %d, s = %d\n", mbits1, mbits2, mbits3, mbits4, out[tmpoutpos-1])

		bitpacking.FastPackWithoutMask(delta, 0, out, tmpoutpos, int(mbits1))
		//encoding.PrintUint32sInBits(in[s:s+32])
		//encoding.PrintUint32sInBits(out[tmpoutpos:tmpoutpos+int(mbits1]))
		tmpoutpos += int(mbits1)

		bitpacking.FastPackWithoutMask(delta, 32, out, tmpoutpos, int(mbits2))
		//encoding.PrintUint32sInBits(in, s+32, 32)
		//encoding.PrintUint32sInBits(out, tmpoutpos, int(mbits2))
		tmpoutpos += int(mbits2)

		bitpacking.FastPackWithoutMask(delta, 64, out, tmpoutpos, int(mbits3))
		//encoding.PrintUint32sInBits(in, s+2*32, 32)
		//encoding.PrintUint32sInBits(out, tmpoutpos, int(mbits3))
		tmpoutpos += int(mbits3)

		bitpacking.FastPackWithoutMask(delta, 96, out, tmpoutpos, int(mbits4))
		//encoding.PrintUint32sInBits(in, s+3*32, 32)
		//encoding.PrintUint32sInBits(out, tmpoutpos, int(mbits4))
		tmpoutpos += int(mbits4)

		//log.Printf("zigzag_bp32/Compress: out = %v\n", out[s:s+DefaultBlockSize])
	}

	inpos.Add(inlength)
	outpos.Set(tmpoutpos)

	return nil
}