Example #1
0
func (this *BP32) Uncompress(in []int32, inpos *cursor.Cursor, inlength int, out []int32, outpos *cursor.Cursor) error {
	if inlength == 0 {
		return errors.New("zigzag_bp32/Uncompress: Length is 0. No work done.")
	}

	outlength := int(in[inpos.Get()])
	inpos.Increment()

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

	//log.Printf("zigzag_bp32/Uncompress: outlength = %d, inpos = %d, outpos = %d\n", outlength, inpos.Get(), outpos.Get())
	for ; s < finalinpos; s += DefaultBlockSize {
		tmp := in[tmpinpos]
		mbits1 := tmp >> 24
		mbits2 := (tmp >> 16) & 0xFF
		mbits3 := (tmp >> 8) & 0xFF
		mbits4 := (tmp) & 0xFF

		//log.Printf("zigzag_bp32/Uncopmress: mbits1 = %d, mbits2 = %d, mbits3 = %d, mbits4 = %d, s = %d\n", mbits1, mbits2, mbits3, mbits4, s)
		tmpinpos += 1

		bitpacking.FastUnpack(in, tmpinpos, delta, 0, int(mbits1))
		tmpinpos += int(mbits1)
		//log.Printf("zigzag_bp32/Uncompress: delta = %v\n", out)

		bitpacking.FastUnpack(in, tmpinpos, delta, 32, int(mbits2))
		tmpinpos += int(mbits2)
		//log.Printf("zigzag_bp32/Uncompress: delta = %v\n", out)

		bitpacking.FastUnpack(in, tmpinpos, delta, 64, int(mbits3))
		tmpinpos += int(mbits3)
		//log.Printf("zigzag_bp32/Uncompress: delta = %v\n", out)

		bitpacking.FastUnpack(in, tmpinpos, delta, 96, int(mbits4))
		tmpinpos += int(mbits4)

		encoding.InverseZigZagDelta(delta, out[s:s+DefaultBlockSize])

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

	}

	outpos.Add(outlength)
	inpos.Set(tmpinpos)

	return nil
}
Example #2
0
func (this *BP32) Uncompress(in []int32, inpos *cursor.Cursor, inlength int, out []int32, outpos *cursor.Cursor) error {
	if inlength == 0 {
		return errors.New("BP32/Uncompress: Length is 0. No work done.")
	}

	outlength := in[inpos.Get()]
	inpos.Increment()

	tmpinpos := inpos.Get()
	initoffset := int32(0)

	//log.Printf("bp32/Uncompress: outlength = %d, inpos = %d, outpos = %d\n", outlength, inpos.Get(), outpos.Get())
	for s := outpos.Get(); s < outpos.Get()+int(outlength); s += 32 * 4 {
		tmp := in[tmpinpos]
		mbits1 := tmp >> 24
		mbits2 := (tmp >> 16) & 0xFF
		mbits3 := (tmp >> 8) & 0xFF
		mbits4 := (tmp) & 0xFF

		//log.Printf("bp32/Uncopmress: mbits1 = %d, mbits2 = %d, mbits3 = %d, mbits4 = %d, s = %d\n", mbits1, mbits2, mbits3, mbits4, s)
		tmpinpos += 1

		bitpacking.DeltaUnpack(initoffset, in, tmpinpos, out, s, int(mbits1))
		tmpinpos += int(mbits1)
		initoffset = out[s+31]
		//log.Printf("bp32/Uncompress: out = %v\n", out)

		bitpacking.DeltaUnpack(initoffset, in, tmpinpos, out, s+32, int(mbits2))
		tmpinpos += int(mbits2)
		initoffset = out[s+32+31]
		//log.Printf("bp32/Uncompress: out = %v\n", out)

		bitpacking.DeltaUnpack(initoffset, in, tmpinpos, out, s+2*32, int(mbits3))
		tmpinpos += int(mbits3)
		initoffset = out[s+2*32+31]
		//log.Printf("bp32/Uncompress: out = %v\n", out)

		bitpacking.DeltaUnpack(initoffset, in, tmpinpos, out, s+3*32, int(mbits4))
		tmpinpos += int(mbits4)
		initoffset = out[s+3*32+31]
		//log.Printf("bp32/Uncompress: out = %v\n", out)
	}

	outpos.Add(int(outlength))
	inpos.Set(tmpinpos)

	return nil
}
Example #3
0
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
}
Example #4
0
func (this *VariableByte) Uncompress(in []int32, inpos *cursor.Cursor, inlength int, out []int32, outpos *cursor.Cursor) error {
	if inlength == 0 {
		return errors.New("variablebyte/Uncompress: inlength = 0. No work done.")
	}

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

	s := uint(0)
	p := inpos.Get()
	finalp := inpos.Get() + inlength
	tmpoutpos := outpos.Get()
	initoffset := int32(0)
	v := int32(0)
	shift := uint(0)

	for p < finalp {
		c := in[p] >> (24 - s)
		s += 8

		if s == 32 {
			s = 0
			p += 1
		}

		v += ((c & 127) << shift)
		if c&128 == 0 {
			out[tmpoutpos] = v + initoffset
			initoffset = out[tmpoutpos]
			tmpoutpos += 1
			v = 0
			shift = 0
		} else {
			shift += 7
		}

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

	return nil
}
Example #5
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 #6
0
func (this *BP32) Uncompress(in []int32, inpos *cursor.Cursor, inlength int, out []int32, outpos *cursor.Cursor) error {
	if inlength == 0 {
		return errors.New("BP32/Uncompress: Length is 0. No work done.")
	}

	outlength := int(in[inpos.Get()])
	inpos.Increment()

	tmpinpos := inpos.Get()

	for s := outpos.Get(); s < outpos.Get()+outlength; s += 32 * 4 {
		tmp := in[tmpinpos]
		mbits1 := tmp >> 24
		mbits2 := (tmp >> 16) & 0xFF
		mbits3 := (tmp >> 8) & 0xFF
		mbits4 := (tmp) & 0xFF

		tmpinpos += 1

		bitpacking.FastUnpack(in, tmpinpos, out, s, int(mbits1))
		tmpinpos += int(mbits1)

		bitpacking.FastUnpack(in, tmpinpos, out, s+32, int(mbits2))
		tmpinpos += int(mbits2)

		bitpacking.FastUnpack(in, tmpinpos, out, s+2*32, int(mbits3))
		tmpinpos += int(mbits3)

		bitpacking.FastUnpack(in, tmpinpos, out, s+3*32, int(mbits4))
		tmpinpos += int(mbits4)
	}

	outpos.Add(outlength)
	inpos.Set(tmpinpos)

	return nil
}
Example #7
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
}
Example #8
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
}