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

@@ -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
//