2026-05-10 00:59:47 +00:00
|
|
|
package chunkenc
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"fmt"
|
|
|
|
|
"testing"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func TestCumdelta(t *testing.T) {
|
|
|
|
|
var (
|
|
|
|
|
fracDigits byte = 0
|
2026-06-05 19:43:01 +00:00
|
|
|
buf = make([]byte, minBufferSize)
|
2026-05-10 00:59:47 +00:00
|
|
|
value float64
|
|
|
|
|
done bool
|
|
|
|
|
)
|
|
|
|
|
c := NewReverseCumulativeDeltaCompressor(buf, 0, fracDigits)
|
|
|
|
|
// c.Append(1.55)
|
|
|
|
|
// c.Append(23)
|
|
|
|
|
// c.Append(23)
|
|
|
|
|
// c.Append(23)
|
|
|
|
|
// c.Append(23.5)
|
|
|
|
|
|
|
|
|
|
c.Append(130)
|
|
|
|
|
c.Append(191)
|
|
|
|
|
|
|
|
|
|
c.Append(248)
|
|
|
|
|
c.Append(305)
|
|
|
|
|
|
|
|
|
|
//fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
//fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
d := NewReverseCumulativeDeltaDecompressor(buf, c.Size(), fracDigits)
|
|
|
|
|
|
|
|
|
|
for range 8 {
|
|
|
|
|
value, done = d.NextValue()
|
|
|
|
|
fmt.Println(value, done)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInsdelta(t *testing.T) {
|
|
|
|
|
var (
|
|
|
|
|
fracDigits byte = 2
|
2026-06-05 19:43:01 +00:00
|
|
|
buf = make([]byte, minBufferSize)
|
2026-05-10 00:59:47 +00:00
|
|
|
value float64
|
|
|
|
|
done bool
|
|
|
|
|
)
|
|
|
|
|
c := NewReverseInstantDeltaCompressor(buf, 0, fracDigits)
|
|
|
|
|
c.Append(-1.55)
|
|
|
|
|
c.Append(23)
|
|
|
|
|
|
|
|
|
|
//fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
//fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
c.Append(23)
|
|
|
|
|
c.Append(23)
|
|
|
|
|
|
|
|
|
|
c.Append(-23.5)
|
|
|
|
|
|
|
|
|
|
//fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
//fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
d := NewReverseInstantDeltaDecompressor(buf, c.Size(), fracDigits)
|
|
|
|
|
|
|
|
|
|
for range 8 {
|
|
|
|
|
value, done = d.NextValue()
|
|
|
|
|
fmt.Println(value, done)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestTimeDelta(t *testing.T) {
|
|
|
|
|
var (
|
2026-06-05 19:43:01 +00:00
|
|
|
buf = make([]byte, minBufferSize)
|
2026-05-10 00:59:47 +00:00
|
|
|
value uint32
|
|
|
|
|
done bool
|
|
|
|
|
)
|
|
|
|
|
c := NewReverseTimeDeltaCompressor(buf, 0)
|
|
|
|
|
c.Append(10)
|
|
|
|
|
|
|
|
|
|
//c.Append(131)
|
|
|
|
|
|
|
|
|
|
//fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
//fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
c.Append(70)
|
|
|
|
|
|
|
|
|
|
c.Append(130)
|
|
|
|
|
c.Append(191)
|
|
|
|
|
|
|
|
|
|
c.Append(248)
|
|
|
|
|
c.Append(305)
|
|
|
|
|
c.Append(330)
|
|
|
|
|
c.Append(390)
|
|
|
|
|
c.Append(450)
|
|
|
|
|
|
|
|
|
|
// fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
// fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
//c.Sync()
|
|
|
|
|
|
2026-05-31 20:01:28 +00:00
|
|
|
// bound := c.GetState()
|
2026-05-10 00:59:47 +00:00
|
|
|
|
2026-05-31 20:01:28 +00:00
|
|
|
// fmt.Println("AFTER SYNC")
|
|
|
|
|
// fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
// chunks := buf.Chunks()
|
|
|
|
|
// if len(chunks) > 0 {
|
|
|
|
|
// fmt.Printf("%d\n", chunks[0])
|
|
|
|
|
// }
|
2026-05-10 00:59:47 +00:00
|
|
|
|
|
|
|
|
d := NewReverseTimeDeltaDecompressor(buf, c.Size())
|
2026-05-31 20:01:28 +00:00
|
|
|
// d.RestoreFromBound(bound)
|
2026-05-10 00:59:47 +00:00
|
|
|
//d.RestoreFromEnd()
|
|
|
|
|
|
|
|
|
|
for range 12 {
|
|
|
|
|
value, done = d.NextValue()
|
|
|
|
|
fmt.Println(value, done)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCumdeltaBound(t *testing.T) {
|
|
|
|
|
var (
|
|
|
|
|
fracDigits byte = 0
|
2026-06-05 19:43:01 +00:00
|
|
|
buf = make([]byte, minBufferSize)
|
2026-05-10 00:59:47 +00:00
|
|
|
value float64
|
|
|
|
|
done bool
|
|
|
|
|
)
|
|
|
|
|
c := NewReverseCumulativeDeltaCompressor(buf, 0, fracDigits)
|
|
|
|
|
// c.Append(1.55)
|
|
|
|
|
// c.Append(23)
|
|
|
|
|
// c.Append(23)
|
|
|
|
|
// c.Append(23)
|
|
|
|
|
// c.Append(23.5)
|
|
|
|
|
c.Append(10)
|
|
|
|
|
c.Append(70)
|
|
|
|
|
|
|
|
|
|
c.Append(130)
|
|
|
|
|
|
|
|
|
|
// fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
// fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
c.Append(191)
|
|
|
|
|
|
|
|
|
|
// fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
// fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
c.Append(191)
|
|
|
|
|
|
|
|
|
|
fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
//////////////////////////
|
|
|
|
|
|
2026-05-10 19:15:11 +00:00
|
|
|
c.Lock()
|
2026-05-10 00:59:47 +00:00
|
|
|
|
2026-05-10 19:15:11 +00:00
|
|
|
//fmt.Printf("bound: pos=%d, h=%d\n", bound.Pos, bound.H)
|
2026-05-10 00:59:47 +00:00
|
|
|
|
|
|
|
|
c.Append(248)
|
|
|
|
|
c.Append(305)
|
|
|
|
|
|
|
|
|
|
fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
d := NewReverseCumulativeDeltaDecompressor(buf, c.Size(), fracDigits)
|
|
|
|
|
d.RestoreFromEnd()
|
|
|
|
|
|
|
|
|
|
for range 8 {
|
|
|
|
|
value, done = d.NextValue()
|
|
|
|
|
fmt.Println(value, done)
|
|
|
|
|
}
|
|
|
|
|
|
2026-05-10 19:15:11 +00:00
|
|
|
//boundDecompressor := NewReverseCumulativeDeltaDecompressor(buf, c.Size(), fracDigits)
|
|
|
|
|
//boundDecompressor.RestoreFromBound(bound)
|
|
|
|
|
boundDecompressor := c.CreateDecompressor(fracDigits)
|
2026-05-10 00:59:47 +00:00
|
|
|
|
|
|
|
|
fmt.Println("from bound:")
|
|
|
|
|
for range 8 {
|
|
|
|
|
value, done = boundDecompressor.NextValue()
|
|
|
|
|
fmt.Println(value, done)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInsdeltaBound(t *testing.T) {
|
|
|
|
|
var (
|
|
|
|
|
fracDigits byte = 0
|
2026-06-05 19:43:01 +00:00
|
|
|
buf = make([]byte, minBufferSize)
|
2026-05-10 00:59:47 +00:00
|
|
|
value float64
|
|
|
|
|
done bool
|
|
|
|
|
)
|
|
|
|
|
c := NewReverseInstantDeltaCompressor(buf, 0, fracDigits)
|
|
|
|
|
// c.Append(1.55)
|
|
|
|
|
// c.Append(23)
|
|
|
|
|
// c.Append(23)
|
|
|
|
|
// c.Append(23)
|
|
|
|
|
// c.Append(23.5)
|
|
|
|
|
c.Append(10)
|
|
|
|
|
c.Append(70)
|
|
|
|
|
|
|
|
|
|
c.Append(130)
|
|
|
|
|
|
|
|
|
|
// fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
// fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
c.Append(191)
|
|
|
|
|
|
|
|
|
|
// fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
// fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
c.Append(191)
|
|
|
|
|
|
|
|
|
|
fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
//////////////////////////
|
|
|
|
|
|
2026-05-31 20:01:28 +00:00
|
|
|
//bound := c.GetState()
|
2026-05-10 00:59:47 +00:00
|
|
|
|
2026-05-31 20:01:28 +00:00
|
|
|
//fmt.Printf("bound: pos=%d, h=%d\n", bound.Pos, bound.H)
|
2026-05-10 00:59:47 +00:00
|
|
|
|
|
|
|
|
c.Append(248)
|
|
|
|
|
c.Append(305)
|
|
|
|
|
|
|
|
|
|
fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
d := NewReverseInstantDeltaDecompressor(buf, c.Size(), fracDigits)
|
|
|
|
|
d.RestoreFromEnd()
|
|
|
|
|
|
|
|
|
|
for range 8 {
|
|
|
|
|
value, done = d.NextValue()
|
|
|
|
|
fmt.Println(value, done)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boundDecompressor := NewReverseInstantDeltaDecompressor(buf, c.Size(), fracDigits)
|
2026-05-31 20:01:28 +00:00
|
|
|
//boundDecompressor.RestoreFromBound(bound)
|
2026-05-10 00:59:47 +00:00
|
|
|
|
|
|
|
|
fmt.Println("from bound:")
|
|
|
|
|
for range 8 {
|
|
|
|
|
value, done = boundDecompressor.NextValue()
|
|
|
|
|
fmt.Println(value, done)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestInsdeltaBound2(t *testing.T) {
|
|
|
|
|
var (
|
|
|
|
|
fracDigits byte = 0
|
2026-06-05 19:43:01 +00:00
|
|
|
buf = make([]byte, minBufferSize)
|
2026-05-10 00:59:47 +00:00
|
|
|
value float64
|
|
|
|
|
done bool
|
|
|
|
|
)
|
|
|
|
|
c := NewReverseInstantDeltaCompressor(buf, 0, fracDigits)
|
|
|
|
|
// c.Append(1.55)
|
|
|
|
|
// c.Append(23)
|
|
|
|
|
// c.Append(23)
|
|
|
|
|
// c.Append(23)
|
|
|
|
|
// c.Append(23.5)
|
|
|
|
|
c.Append(305)
|
|
|
|
|
c.Append(248)
|
|
|
|
|
|
|
|
|
|
c.Append(191)
|
|
|
|
|
|
|
|
|
|
// fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
// fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
c.Append(191)
|
|
|
|
|
|
|
|
|
|
// fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
// fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
c.Append(130)
|
|
|
|
|
|
|
|
|
|
fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
//////////////////////////
|
|
|
|
|
|
2026-05-31 20:01:28 +00:00
|
|
|
//bound := c.GetState()
|
2026-05-10 00:59:47 +00:00
|
|
|
|
2026-05-31 20:01:28 +00:00
|
|
|
//fmt.Printf("bound: pos=%d, h=%d\n", bound.Pos, bound.H)
|
2026-05-10 00:59:47 +00:00
|
|
|
|
|
|
|
|
c.Append(70)
|
|
|
|
|
c.Append(10)
|
|
|
|
|
|
|
|
|
|
fmt.Printf("pos: %d\n", c.pos)
|
|
|
|
|
fmt.Printf("%d\n", buf.Chunks()[0])
|
|
|
|
|
|
|
|
|
|
d := NewReverseInstantDeltaDecompressor(buf, c.Size(), fracDigits)
|
|
|
|
|
d.RestoreFromEnd()
|
|
|
|
|
|
|
|
|
|
for range 8 {
|
|
|
|
|
value, done = d.NextValue()
|
|
|
|
|
fmt.Println(value, done)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boundDecompressor := NewReverseInstantDeltaDecompressor(buf, c.Size(), fracDigits)
|
2026-05-31 20:01:28 +00:00
|
|
|
//sboundDecompressor.RestoreFromBound(bound)
|
2026-05-10 00:59:47 +00:00
|
|
|
|
|
|
|
|
fmt.Println("from bound:")
|
|
|
|
|
for range 8 {
|
|
|
|
|
value, done = boundDecompressor.NextValue()
|
|
|
|
|
fmt.Println(value, done)
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-06-05 19:43:01 +00:00
|
|
|
|
|
|
|
|
func TestCap(t *testing.T) {
|
|
|
|
|
a := make([]byte, 0, 10)
|
|
|
|
|
fmt.Println("len:", len(a))
|
|
|
|
|
fmt.Println("cap:", cap(a))
|
|
|
|
|
|
|
|
|
|
a = append(a, 1)
|
|
|
|
|
fmt.Println("after append:")
|
|
|
|
|
fmt.Println("len:", len(a))
|
|
|
|
|
fmt.Println("cap:", cap(a))
|
|
|
|
|
fmt.Println("a:", a)
|
|
|
|
|
|
|
|
|
|
a[1] = 55
|
|
|
|
|
fmt.Println("after []:")
|
|
|
|
|
fmt.Println("len:", len(a))
|
|
|
|
|
fmt.Println("cap:", cap(a))
|
|
|
|
|
fmt.Println("a:", a)
|
|
|
|
|
|
|
|
|
|
a = append(a, 2)
|
|
|
|
|
fmt.Println("after 2nd append:")
|
|
|
|
|
fmt.Println("len:", len(a))
|
|
|
|
|
fmt.Println("cap:", cap(a))
|
|
|
|
|
fmt.Println("a:", a)
|
|
|
|
|
}
|