diff --git a/chunks/chunk_test.go b/chunks/chunk_test.go index bbaa6d140..7292e4cbe 100644 --- a/chunks/chunk_test.go +++ b/chunks/chunk_test.go @@ -94,10 +94,10 @@ func benchmarkIterator(b *testing.B, newChunk func(int) Chunk) { ) var exp []pair for i := 0; i < b.N; i++ { - // t += int64(rand.Intn(10000) + 1) - t += int64(1000) + t += int64(rand.Intn(10000) + 1) + // t += int64(1000) // v = rand.Float64() - // v += float64(100) + v += float64(100) exp = append(exp, pair{t: t, v: v}) } @@ -161,10 +161,10 @@ func benchmarkAppender(b *testing.B, newChunk func(int) Chunk) { ) var exp []pair for i := 0; i < b.N; i++ { - // t += int64(rand.Intn(10000) + 1) - t += int64(1000) + t += int64(rand.Intn(10000) + 1) + // t += int64(1000) // v = rand.Float64() - // v += float64(100) + v += float64(100) exp = append(exp, pair{t: t, v: v}) } diff --git a/chunks/xor.go b/chunks/xor.go index 4885f2956..1b136ca3a 100644 --- a/chunks/xor.go +++ b/chunks/xor.go @@ -120,13 +120,13 @@ func (a *xorAppender) Append(t int64, v float64) error { switch { case dod == 0: a.b.writeBit(zero) - case -8191 <= dod && dod <= 8192: + case bitRange(dod, 14): a.b.writeBits(0x02, 2) // '10' a.b.writeBits(uint64(dod), 14) - case -65535 <= dod && dod <= 65536: + case bitRange(dod, 17): a.b.writeBits(0x06, 3) // '110' a.b.writeBits(uint64(dod), 17) - case -524287 <= dod && dod <= 524288: + case bitRange(dod, 20): a.b.writeBits(0x0e, 4) // '1110' a.b.writeBits(uint64(dod), 20) default: @@ -152,6 +152,10 @@ func (a *xorAppender) Append(t int64, v float64) error { return nil } +func bitRange(x int64, nbits uint8) bool { + return -((1<<(nbits-1))-1) <= x && x <= 1<<(nbits-1) +} + func (a *xorAppender) writeVDelta(v float64) { vDelta := math.Float64bits(v) ^ math.Float64bits(a.v)