Example #1
0
func timePack(deltaSample, tPrev, tCurr int64) (length uint, packed uint64) {
	tDelta := tCurr - tPrev
	packVal := tDelta - deltaSample

	if packVal == 0 {
		return 1, 0
	}

	if packVal >= -31 && packVal <= 31 {
		packed, _ = bitopts.SetBit64(packed, 63)
		if packVal < 0 {
			packVal = -packVal
			packed, _ = bitopts.SetBit64(packed, 62)
		}
		packed, _ = bitopts.SetField64(packed, 61, 57, uint64(packVal))
	} else {
		panic("unable to pack time")
	}

	return 7, packed >> (64 - 7)
}
Example #2
0
// Pack a floating point value change for placement into a uint64 "bit-stream"
//
// If there is no change, packed value is a one-bit long value of 0
// If there is change, packed value is a variable-length bit value:
//	1-bits - Set to 1
//	5-bits - Number of leading zeros in XOR of fPrev and fCurr
//	6-bits - Length of significant bits of XOR of fPrev and fCurr
//	X-bits - Value of XOR of fPrev and fCurr
//
// Packed value is returned such that the LSB of packed value starts at bit 0
// (that is, the packed value is shifted such that there are a bunch of leading
// zeros in the MSB before the first bit, which is set to 1 in the case of a change)
func valuePack(fPrev, fCurr float32) (length uint, packed uint64) {
	xorval := (*(*uint32)(unsafe.Pointer(&fPrev))) ^ (*(*uint32)(unsafe.Pointer(&fCurr)))

	if xorval == 0 {
		return 1, 0
	}

	leadzeroLen := countLeadingZero32(xorval)
	trailzeroLen := countTrailingZero32(xorval)
	sigbitLen := 32 - (leadzeroLen + trailzeroLen)

	packed, _ = bitopts.SetBit64(packed, 63)
	packed, _ = bitopts.SetField64(packed, 62, 58, uint64(leadzeroLen))
	packed, _ = bitopts.SetField64(packed, 57, 52, uint64(sigbitLen))
	packed, _ = bitopts.SetField64(packed, 51, 51-(sigbitLen-1), uint64(xorval)>>trailzeroLen)

	packLen := sigbitLen + 12

	return packLen, packed >> (64 - packLen)
}