This commit is contained in:
2026-05-31 20:01:28 +00:00
parent e7ec6083cb
commit db5ecd3dfd
28 changed files with 2090 additions and 2155 deletions

View File

@@ -98,17 +98,17 @@ func TestTimeDelta(t *testing.T) {
//c.Sync()
bound := c.GetState()
// 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])
}
// 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.RestoreFromBound(bound)
//d.RestoreFromEnd()
for range 12 {
@@ -210,9 +210,9 @@ func TestInsdeltaBound(t *testing.T) {
fmt.Printf("%d\n", buf.Chunks()[0])
//////////////////////////
bound := c.GetState()
//bound := c.GetState()
fmt.Printf("bound: pos=%d, h=%d\n", bound.Pos, bound.H)
//fmt.Printf("bound: pos=%d, h=%d\n", bound.Pos, bound.H)
c.Append(248)
c.Append(305)
@@ -229,7 +229,7 @@ func TestInsdeltaBound(t *testing.T) {
}
boundDecompressor := NewReverseInstantDeltaDecompressor(buf, c.Size(), fracDigits)
boundDecompressor.RestoreFromBound(bound)
//boundDecompressor.RestoreFromBound(bound)
fmt.Println("from bound:")
for range 8 {
@@ -270,9 +270,9 @@ func TestInsdeltaBound2(t *testing.T) {
fmt.Printf("%d\n", buf.Chunks()[0])
//////////////////////////
bound := c.GetState()
//bound := c.GetState()
fmt.Printf("bound: pos=%d, h=%d\n", bound.Pos, bound.H)
//fmt.Printf("bound: pos=%d, h=%d\n", bound.Pos, bound.H)
c.Append(70)
c.Append(10)
@@ -289,7 +289,7 @@ func TestInsdeltaBound2(t *testing.T) {
}
boundDecompressor := NewReverseInstantDeltaDecompressor(buf, c.Size(), fracDigits)
boundDecompressor.RestoreFromBound(bound)
//sboundDecompressor.RestoreFromBound(bound)
fmt.Println("from bound:")
for range 8 {

View File

@@ -5,6 +5,7 @@ import (
"log"
"math"
"gordenko.dev/dima/qb"
"gordenko.dev/dima/qb/conbuf"
)
@@ -180,15 +181,58 @@ type CumulativeDeltaBound struct {
// delta h
func (s *ReverseCumulativeDeltaCompressor) Lock() {
if s.state != nil {
qb.Abort(qb.RepeatableLock, nil)
}
// позиція посувається вліво, отже може перескочити на попередній chunk
pos := s.pos - 1 - s.lastDeltaSize
chunksQty := pos / conbuf.ChunkSize
if (pos % conbuf.ChunkSize) > 0 {
chunksQty++
}
s.state = &CumulativeDeltaBound{
Pos: s.pos - 1 - s.lastDeltaSize,
Pos: pos,
H: s.h,
LastDelta: s.lastDelta,
Chunks: s.buf.Chunks(),
Chunks: s.buf.Chunks()[:chunksQty],
}
}
func (s *ReverseCumulativeDeltaCompressor) CreateDecompressor(fracDigits byte) *ReverseCumulativeDeltaDecompressor {
// fix - повернути в Pool буфери
func (s *ReverseCumulativeDeltaCompressor) Unlock() {
s.state = nil
}
func (s *ReverseCumulativeDeltaCompressor) Offset() int {
if s.state != nil {
return s.state.Pos
}
return 0
}
func (s *ReverseCumulativeDeltaCompressor) Snapshot() ([][]byte, int) {
if s.state == nil {
return s.buf.Chunks(), s.Size()
}
// ВАЖЛИВО!
// Треба відтворити стан останнього чанка
var (
pos = s.state.Pos
chunk = make([]byte, conbuf.ChunkSize)
lastChunkIdx = len(s.state.Chunks) - 1
qtyToCopy = pos % conbuf.ChunkSize
)
copy(chunk, s.state.Chunks[lastChunkIdx][:qtyToCopy])
chunks := append(s.state.Chunks[:lastChunkIdx], chunk)
buf := conbuf.New(chunks)
pos += buf.ReversePutVarUint64(pos, s.state.LastDelta)
buf.SetByte(pos, s.state.H)
pos++
return chunks, pos
}
func (s *ReverseCumulativeDeltaCompressor) CreateDecompressor(fracDigits byte) qb.ValueDecompressor {
if s.state == nil {
d := NewReverseCumulativeDeltaDecompressor(s.buf, s.Size(), fracDigits)
d.RestoreFromEnd()
@@ -199,11 +243,9 @@ func (s *ReverseCumulativeDeltaCompressor) CreateDecompressor(fracDigits byte) *
return d
}
func (s *ReverseCumulativeDeltaCompressor) Unlock() {
s.state = nil
}
func (s *ReverseCumulativeDeltaCompressor) Renew() {
// УВАГА!
// state не чіпаємо
s.buf = conbuf.New(nil)
s.pos = 0
//

View File

@@ -5,6 +5,7 @@ import (
"log"
"math"
"gordenko.dev/dima/qb"
"gordenko.dev/dima/qb/conbuf"
)
@@ -16,6 +17,7 @@ type ReverseInstantDeltaCompressor struct {
lastDelta int64
lastDeltaSize int
h byte
state *InstantDeltaBound
}
func NewReverseInstantDeltaCompressor(buf *conbuf.ContinuousBuffer, size int, fracDigits byte) *ReverseInstantDeltaCompressor {
@@ -147,30 +149,76 @@ type InstantDeltaBound struct {
Pos int
H byte
LastDelta int64
Chunks [][]byte
}
func (s *ReverseInstantDeltaCompressor) GetState() InstantDeltaBound {
return InstantDeltaBound{
Pos: s.pos - 1 - s.lastDeltaSize,
// delta h
func (s *ReverseInstantDeltaCompressor) Lock() {
if s.state != nil {
qb.Abort(qb.RepeatableLock, nil)
}
// позиція посувається вліво, отже може перескочити на попередній chunk
pos := s.pos - 1 - s.lastDeltaSize
chunksQty := pos / conbuf.ChunkSize
if (pos % conbuf.ChunkSize) > 0 {
chunksQty++
}
s.state = &InstantDeltaBound{
Pos: pos,
H: s.h,
LastDelta: s.lastDelta,
Chunks: s.buf.Chunks()[:chunksQty],
}
}
func (s *ReverseInstantDeltaCompressor) Lock() {
// s.state = &CumulativeDeltaBound{
// Pos: s.pos - 1 - s.lastDeltaSize,
// H: s.h,
// LastDelta: s.lastDelta,
// Chunks: s.buf.Chunks(),
// }
// fix - повернути в Pool буфери
func (s *ReverseInstantDeltaCompressor) Unlock() {
s.state = nil
}
func (s *ReverseInstantDeltaCompressor) Unlock() {
//s.state = nil
func (s *ReverseInstantDeltaCompressor) Offset() int {
if s.state != nil {
return s.state.Pos
}
return 0
}
func (s *ReverseInstantDeltaCompressor) Snapshot() ([][]byte, int) {
if s.state == nil {
return s.buf.Chunks(), s.Size()
}
// ВАЖЛИВО!
// Треба відтворити стан останнього чанка
var (
pos = s.state.Pos
chunk = make([]byte, conbuf.ChunkSize)
lastChunkIdx = len(s.state.Chunks) - 1
qtyToCopy = pos % conbuf.ChunkSize
)
copy(chunk, s.state.Chunks[lastChunkIdx][:qtyToCopy])
chunks := append(s.state.Chunks[:lastChunkIdx], chunk)
buf := conbuf.New(chunks)
pos += buf.ReversePutVarInt64(pos, s.state.LastDelta)
buf.SetByte(pos, s.state.H)
pos++
return chunks, pos
}
func (s *ReverseInstantDeltaCompressor) CreateDecompressor(fracDigits byte) qb.ValueDecompressor {
if s.state == nil {
d := NewReverseInstantDeltaDecompressor(s.buf, s.Size(), fracDigits)
d.RestoreFromEnd()
return d
}
d := NewReverseInstantDeltaDecompressor(s.buf, s.Size(), fracDigits)
d.RestoreFromBound(*s.state)
return d
}
func (s *ReverseInstantDeltaCompressor) Renew() {
// УВАГА!
// state не чіпаємо
s.buf = conbuf.New(nil)
s.pos = 0
//

View File

@@ -5,6 +5,7 @@ import (
"log"
"gordenko.dev/dima/pretty"
"gordenko.dev/dima/qb"
"gordenko.dev/dima/qb/conbuf"
)
@@ -15,6 +16,7 @@ type ReverseTimeDeltaCompressor struct {
lastDelta uint32
lastDeltaSize int
h byte
state *TimeDeltaBound
}
func NewReverseTimeDeltaCompressor(buf *conbuf.ContinuousBuffer, size int) *ReverseTimeDeltaCompressor {
@@ -45,10 +47,6 @@ func (s *ReverseTimeDeltaCompressor) Size() int {
return s.pos
}
func (s *ReverseTimeDeltaCompressor) Chunks() [][]byte {
return s.buf.Chunks()
}
func (s *ReverseTimeDeltaCompressor) CalcRequiredSpace(value uint32) int {
return 0
}
@@ -151,42 +149,109 @@ func (s *ReverseTimeDeltaCompressor) Sync() {
s.pos += s.buf.ReversePutVarUint64(s.pos, uint64(s.lastUnixtime))
}
// FIX - check methods
type TimeDeltaBound struct {
Pos int
H byte
LastUnixtime uint32
LastDelta uint32
Chunks [][]byte
}
// delta h
func (s *ReverseTimeDeltaCompressor) GetState() TimeDeltaBound { // fix replace by Lock
bound := TimeDeltaBound{
LastUnixtime: s.lastUnixtime,
}
if s.pos > 0 {
bound.Pos = s.pos - 1 - s.lastDeltaSize
bound.H = s.h
bound.LastDelta = s.lastDelta
}
return bound
}
// func (s *ReverseTimeDeltaCompressor) GetState() TimeDeltaBound { // fix replace by Lock
// bound := TimeDeltaBound{
// LastUnixtime: s.lastUnixtime,
// }
// if s.pos > 0 {
// bound.Pos = s.pos - 1 - s.lastDeltaSize
// bound.H = s.h
// bound.LastDelta = s.lastDelta
// }
// return bound
// }
// delta h
func (s *ReverseTimeDeltaCompressor) Lock() {
// fix
if s.state != nil {
qb.Abort(qb.RepeatableLock, nil)
}
// позиція посувається вліво, отже може перескочити на попередній chunk
pos := s.pos - 1 - s.lastDeltaSize
chunksQty := pos / conbuf.ChunkSize
if (pos % conbuf.ChunkSize) > 0 {
chunksQty++
}
s.state = &TimeDeltaBound{
Pos: pos,
H: s.h,
LastUnixtime: s.lastUnixtime, // fix
LastDelta: s.lastDelta,
Chunks: s.buf.Chunks()[:chunksQty],
}
}
// fix - повернути в Pool буфери
func (s *ReverseTimeDeltaCompressor) Unlock() {
//s.state = nil // fix
s.state = nil
}
func (s *ReverseTimeDeltaCompressor) Offset() int {
if s.state != nil {
return s.state.Pos
}
return 0
}
// fix -
func (s *ReverseTimeDeltaCompressor) Snapshot() ([][]byte, int) {
if s.state == nil {
return s.buf.Chunks(), s.Size()
}
// ВАЖЛИВО!
// Треба відтворити стан останнього чанка
var (
pos = s.state.Pos
chunk = make([]byte, conbuf.ChunkSize)
lastChunkIdx = len(s.state.Chunks) - 1
qtyToCopy = pos % conbuf.ChunkSize
)
copy(chunk, s.state.Chunks[lastChunkIdx][:qtyToCopy])
chunks := append(s.state.Chunks[:lastChunkIdx], chunk)
buf := conbuf.New(chunks)
pos += buf.ReversePutVarUint64(pos, uint64(s.state.LastDelta))
buf.SetByte(pos, s.state.H)
pos++
return chunks, pos
}
func (s *ReverseTimeDeltaCompressor) CreateDecompressor() qb.TimestampDecompressor {
if s.state == nil {
d := NewReverseTimeDeltaDecompressor(s.buf, s.Size())
d.RestoreFromEnd()
return d
}
d := NewReverseTimeDeltaDecompressor(s.buf, s.Size())
d.RestoreFromBound(*s.state)
return d
}
func (s *ReverseTimeDeltaCompressor) Renew() {
// s.buf = conbuf.New(nil)
// s.pos = 0
// //
// s.baseValue = 0
// s.lastDelta = 0
// s.lastDeltaSize = 0
// s.h = 0
// УВАГА!
// state не чіпаємо
s.buf = conbuf.New(nil)
s.pos = 0
//
//s.baseValue = 0
s.lastDelta = 0
s.lastDeltaSize = 0
s.h = 0
}
func (s *ReverseTimeDeltaCompressor) Chunks() [][]byte {
return s.buf.Chunks()
}
// DECOMPRESSOR