package chunkenc import ( "fmt" "testing" "gordenko.dev/dima/qb/conbuf" ) func TestCumdelta(t *testing.T) { var ( fracDigits byte = 0 buf = conbuf.New(nil) 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 buf = conbuf.New(nil) 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 ( buf = conbuf.New(nil) 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() bound := c.GetState() fmt.Println("AFTER SYNC") fmt.Printf("pos: %d\n", c.pos) chunks := buf.Chunks() if len(chunks) > 0 { fmt.Printf("%d\n", chunks[0]) } d := NewReverseTimeDeltaDecompressor(buf, c.Size()) d.RestoreFromBound(bound) //d.RestoreFromEnd() for range 12 { value, done = d.NextValue() fmt.Println(value, done) } } func TestCumdeltaBound(t *testing.T) { var ( fracDigits byte = 0 buf = conbuf.New(nil) 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]) ////////////////////////// c.Lock() //fmt.Printf("bound: pos=%d, h=%d\n", bound.Pos, bound.H) 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) } //boundDecompressor := NewReverseCumulativeDeltaDecompressor(buf, c.Size(), fracDigits) //boundDecompressor.RestoreFromBound(bound) boundDecompressor := c.CreateDecompressor(fracDigits) fmt.Println("from bound:") for range 8 { value, done = boundDecompressor.NextValue() fmt.Println(value, done) } } func TestInsdeltaBound(t *testing.T) { var ( fracDigits byte = 0 buf = conbuf.New(nil) 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]) ////////////////////////// bound := c.GetState() fmt.Printf("bound: pos=%d, h=%d\n", bound.Pos, bound.H) 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) boundDecompressor.RestoreFromBound(bound) fmt.Println("from bound:") for range 8 { value, done = boundDecompressor.NextValue() fmt.Println(value, done) } } func TestInsdeltaBound2(t *testing.T) { var ( fracDigits byte = 0 buf = conbuf.New(nil) 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]) ////////////////////////// bound := c.GetState() fmt.Printf("bound: pos=%d, h=%d\n", bound.Pos, bound.H) 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) boundDecompressor.RestoreFromBound(bound) fmt.Println("from bound:") for range 8 { value, done = boundDecompressor.NextValue() fmt.Println(value, done) } }