Beispiel #1
0
func (this *FastPFOR) 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("fastpfor/Compress: inlength = 0. No work done.")
	}

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

	initoffset := cursor.New()

	copy(this.dataPointers, zeroDataPointers)
	copy(this.freqs, zeroFreqs)

	finalInpos := inpos.Get() + inlength

	for inpos.Get() != finalInpos {
		thissize := int(math.Min(float64(this.pageSize), float64(finalInpos-inpos.Get())))

		if err := this.encodePage(in, inpos, thissize, out, outpos, initoffset); err != nil {
			return errors.New("fastpfor/Compress: " + err.Error())
		}
	}

	return nil
}
Beispiel #2
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
}
Beispiel #3
0
func (this *BP32) Compress(in []int32, inpos *cursor.Cursor, inlength int, out []int32, outpos *cursor.Cursor) error {
	//log.Printf("bp32/Compress: before inlength = %d\n", inlength)

	inlength = encoding.FloorBy(inlength, DefaultBlockSize)

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

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

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

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

	for ; s < finalinpos; s += DefaultBlockSize {
		mbits1 := encoding.DeltaMaxBits(initoffset, in[s:s+32])
		initoffset2 := in[s+31]
		mbits2 := encoding.DeltaMaxBits(initoffset2, in[s+32:s+2*32])
		initoffset3 := in[s+32+31]
		mbits3 := encoding.DeltaMaxBits(initoffset3, in[s+2*32:s+3*32])
		initoffset4 := in[s+2*32+31]
		mbits4 := encoding.DeltaMaxBits(initoffset4, in[s+3*32:s+4*32])

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

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

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

		bitpacking.DeltaPack(initoffset, in, s, out, tmpoutpos, int(mbits1))
		//encoding.PrintUint32sInBits(in, s, 32)
		//encoding.PrintUint32sInBits(out, tmpoutpos, int(mbits1))
		tmpoutpos += int(mbits1)

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

		bitpacking.DeltaPack(initoffset3, in, s+2*32, out, tmpoutpos, int(mbits3))
		//encoding.PrintUint32sInBits(in, s+2*32, 32)
		//encoding.PrintUint32sInBits(out, tmpoutpos, int(mbits3))
		tmpoutpos += int(mbits3)

		bitpacking.DeltaPack(initoffset4, in, s+3*32, out, tmpoutpos, int(mbits4))
		//encoding.PrintUint32sInBits(in, s+3*32, 32)
		//encoding.PrintUint32sInBits(out, tmpoutpos, int(mbits4))
		tmpoutpos += int(mbits4)

		initoffset = in[s+3*32+31]
	}

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

	return nil
}
Beispiel #4
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
}