Ejemplo n.º 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
}
Ejemplo n.º 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 := 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
}
Ejemplo n.º 3
0
func (this *FastPFOR) decodePage(in []int32, inpos *cursor.Cursor, out []int32, outpos *cursor.Cursor, thissize int, initoffset *cursor.Cursor) error {
	initpos := int32(inpos.Get())
	wheremeta := in[initpos]
	inpos.Increment()

	inexcept := initpos + wheremeta
	bytesize := in[inexcept]
	inexcept += 1

	this.byteContainer.Clear()
	if err := this.byteContainer.AsInt32Buffer().PutInt32s(in, int(inexcept), int(bytesize/4)); err != nil {
		return err
	}

	inexcept += bytesize / 4
	bitmap := in[inexcept]
	inexcept += 1

	for k := int32(1); k < 33; k++ {
		if bitmap&(1<<uint32(k-1)) != 0 {
			size := in[inexcept]
			inexcept += 1

			if int32(len(this.dataToBePacked[k])) < size {
				this.dataToBePacked[k] = make([]int32, encoding.CeilBy(int(size), 32))
			}

			for j := int32(0); j < size; j += 32 {
				bitpacking.FastUnpack(in, int(inexcept), this.dataToBePacked[k], int(j), int(k))
				inexcept += k
			}
		}
	}

	copy(this.dataPointers, zeroDataPointers)
	tmpoutpos := int32(outpos.Get())
	tmpinpos := int32(inpos.Get())

	delta := make([]int32, DefaultBlockSize)

	run := 0
	run_end := thissize / DefaultBlockSize
	for run < run_end {
		var err error
		var bestb int32
		if bestb, err = this.byteContainer.GetAsInt32(); err != nil {
			return err
		}

		var cexcept int32
		if cexcept, err = this.byteContainer.GetAsInt32(); err != nil {
			return err
		}

		for k := int32(0); k < 128; k += 32 {
			//bitpacking.FastUnpack(in, int(tmpinpos), out, int(tmpoutpos+k), int(bestb))
			bitpacking.FastUnpack(in, int(tmpinpos), delta, int(k), int(bestb))
			tmpinpos += bestb
		}

		if cexcept > 0 {
			var maxbits int32
			if maxbits, err = this.byteContainer.GetAsInt32(); err != nil {
				return err
			}

			index := maxbits - bestb

			for k := int32(0); k < cexcept; k++ {
				var pos int32
				if pos, err = this.byteContainer.GetAsInt32(); err != nil {
					return err
				}

				exceptvalue := this.dataToBePacked[index][this.dataPointers[index]]
				this.dataPointers[index] += 1
				//out[pos + tmpoutpos] |= exceptvalue << uint(bestb)
				delta[pos] |= exceptvalue << uint(bestb)
			}
		}

		// Calculate the original from the deltas, inlining to gain a bit of performance
		offset := int32(initoffset.Get())
		for i, v := range delta {
			n := int32(uint32(v)>>1) ^ ((v << 31) >> 31)
			out[int(tmpoutpos)+i] = n + offset
			offset += n
		}
		initoffset.Set(int(out[tmpoutpos+DefaultBlockSize-1]))

		run += 1
		tmpoutpos += DefaultBlockSize
	}

	outpos.Set(int(tmpoutpos))
	inpos.Set(int(inexcept))

	return nil
}
Ejemplo n.º 4
0
func (this *FastPFOR) decodePage(in []int32, inpos *cursor.Cursor, out []int32, outpos *cursor.Cursor, thissize int) error {
	initpos := int32(inpos.Get())
	wheremeta := in[initpos]
	inpos.Increment()

	inexcept := initpos + wheremeta
	bytesize := in[inexcept]
	inexcept += 1
	mybytearray := in[inexcept:]
	mybp := uint(0)

	inexcept += (bytesize + 3) / 4
	bitmap := in[inexcept]
	inexcept += 1

	for k := int32(1); k < 33; k++ {
		if bitmap&(1<<uint32(k-1)) != 0 {
			size := in[inexcept]
			inexcept += 1

			if int32(len(this.dataToBePacked[k])) < size {
				this.dataToBePacked[k] = make([]int32, encoding.CeilBy(int(size), 32))
			}
			for j := int32(0); j < size; j += 32 {
				bitpacking.FastUnpack(in, int(inexcept), this.dataToBePacked[k], int(j), int(k))
				inexcept += k
			}
		}
	}

	copy(this.dataPointers, zeroDataPointers)
	tmpoutpos := uint32(outpos.Get())
	tmpinpos := uint32(inpos.Get())

	run := 0
	run_end := thissize / DefaultBlockSize
	for run < run_end {
		bestb := uint32(grapByte(mybytearray, mybp))
		mybp++
		cexcept := int32(grapByte(mybytearray, mybp))
		mybp++
		for k := uint32(0); k < 128; k += 32 {
			bitpacking.FastUnpack(in, int(tmpinpos), out, int(tmpoutpos+k), int(bestb))
			tmpinpos += bestb
		}

		if cexcept > 0 {
			maxbits := uint32(grapByte(mybytearray, mybp))
			mybp++
			index := maxbits - bestb
			// assuming that the Go compiler is bad, we move everything that is indexed outside the upcoming loop
			packedexceptions := this.dataToBePacked[index]
			myindex := this.dataPointers[index]

			for k := int32(0); k < cexcept; k++ {
				pos := uint32(grapByte(mybytearray, mybp))
				mybp++
				exceptvalue := packedexceptions[myindex]
				myindex++
				out[pos+tmpoutpos] |= exceptvalue << bestb
			}
			this.dataPointers[index] = myindex
		}

		run += 1
		tmpoutpos += DefaultBlockSize
	}

	outpos.Set(int(tmpoutpos))
	inpos.Set(int(inexcept))

	return nil
}