This commit is contained in:
2026-06-07 01:06:16 +00:00
parent 0e019118c2
commit 776a341c57
9 changed files with 738 additions and 747 deletions

View File

@@ -37,7 +37,7 @@ v1 v2 v3 h-byte(literal, 3) <- v3
v1 v2 h-byte(literal, 2) v3 h-byte(run, 2)
*/
type ReverseCumulativeDeltaCompressor struct {
type CumulativeDeltaCompressor struct {
buf []byte
coef float64
pos int
@@ -48,12 +48,12 @@ type ReverseCumulativeDeltaCompressor struct {
state *CumulativeDeltaBound
}
func NewReverseCumulativeDeltaCompressor(buf []byte, size int, fracDigits byte) *ReverseCumulativeDeltaCompressor {
func NewCumulativeDeltaCompressor(buf []byte, size int, fracDigits byte) *CumulativeDeltaCompressor {
var coef float64 = 1
if fracDigits > 0 {
coef = math.Pow(10, float64(fracDigits))
}
s := &ReverseCumulativeDeltaCompressor{
s := &CumulativeDeltaCompressor{
buf: buf,
pos: size, // перший вільний байт
coef: coef,
@@ -73,15 +73,15 @@ func NewReverseCumulativeDeltaCompressor(buf []byte, size int, fracDigits byte)
return s
}
func (s *ReverseCumulativeDeltaCompressor) Size() int {
func (s *CumulativeDeltaCompressor) Size() int {
return s.pos
}
func (s *ReverseCumulativeDeltaCompressor) CalcRequiredSpace(value float64) int {
func (s *CumulativeDeltaCompressor) CalcRequiredSpace(value float64) int {
return 0
}
func (s *ReverseCumulativeDeltaCompressor) Append(value float64) {
func (s *CumulativeDeltaCompressor) Append(value float64) {
if s.pos == 0 {
// base value
n, _ := bin.PutVarUint64(s.buf[s.pos:], uint64(value*s.coef))
@@ -131,7 +131,7 @@ func (s *ReverseCumulativeDeltaCompressor) Append(value float64) {
}
}
func (s *ReverseCumulativeDeltaCompressor) convertLastFromLiteralToRun() {
func (s *CumulativeDeltaCompressor) convertLastFromLiteralToRun() {
// Зменшую кількість елементів в literal блоці
s.h--
s.pos -= 1 + s.lastDeltaSize
@@ -144,13 +144,13 @@ func (s *ReverseCumulativeDeltaCompressor) convertLastFromLiteralToRun() {
s.pos++
}
func (s *ReverseCumulativeDeltaCompressor) convertLiteralToRun() {
func (s *CumulativeDeltaCompressor) convertLiteralToRun() {
// Знімаю flagLiteral, а лічильник 0 дорівнює 2 елементам в серії.
s.h = 0
s.buf[s.pos-1] = s.h
}
func (s *ReverseCumulativeDeltaCompressor) appendDeltaToLiteral(delta uint64) {
func (s *CumulativeDeltaCompressor) appendDeltaToLiteral(delta uint64) {
s.h++ // збільшую к-сть дельт
s.lastDelta = delta
s.pos--
@@ -160,7 +160,7 @@ func (s *ReverseCumulativeDeltaCompressor) appendDeltaToLiteral(delta uint64) {
s.pos++
}
func (s *ReverseCumulativeDeltaCompressor) appendNewLiteral(delta uint64) {
func (s *CumulativeDeltaCompressor) appendNewLiteral(delta uint64) {
s.h = flagLiteral
s.lastDelta = delta
s.lastDeltaSize, _ = bin.ReversePutVarUint64(s.buf[s.pos:], delta)
@@ -169,7 +169,7 @@ func (s *ReverseCumulativeDeltaCompressor) appendNewLiteral(delta uint64) {
s.pos++
}
func (s *ReverseCumulativeDeltaCompressor) DeleteLast() {
func (s *CumulativeDeltaCompressor) DeleteLast() {
}
@@ -181,7 +181,7 @@ type CumulativeDeltaBound struct {
}
// delta h
func (s *ReverseCumulativeDeltaCompressor) Lock() {
func (s *CumulativeDeltaCompressor) Lock() {
if s.state != nil {
qb.Abort(qb.RepeatableLock, nil)
}
@@ -196,18 +196,18 @@ func (s *ReverseCumulativeDeltaCompressor) Lock() {
}
// fix - повернути в Pool буфери
func (s *ReverseCumulativeDeltaCompressor) Unlock() {
func (s *CumulativeDeltaCompressor) Unlock() {
s.state = nil
}
func (s *ReverseCumulativeDeltaCompressor) Offset() int {
func (s *CumulativeDeltaCompressor) Offset() int {
if s.state != nil {
return s.state.Pos
}
return 0
}
func (s *ReverseCumulativeDeltaCompressor) Snapshot() ([]byte, int) {
func (s *CumulativeDeltaCompressor) Snapshot() ([]byte, int) {
// if s.state == nil {
// return s.buf, s.Size()
// }
@@ -230,18 +230,18 @@ func (s *ReverseCumulativeDeltaCompressor) Snapshot() ([]byte, int) {
return nil, 0
}
func (s *ReverseCumulativeDeltaCompressor) CreateDecompressor(fracDigits byte) qb.ValueDecompressor {
func (s *CumulativeDeltaCompressor) CreateDecompressor(fracDigits byte) qb.ValueDecompressor {
if s.state == nil {
d := NewReverseCumulativeDeltaDecompressor(s.buf, s.Size(), fracDigits)
d := NewCumulativeDeltaDecompressor(s.buf, s.Size(), fracDigits)
d.RestoreFromEnd()
return d
}
d := NewReverseCumulativeDeltaDecompressor(s.buf, s.Size(), fracDigits)
d := NewCumulativeDeltaDecompressor(s.buf, s.Size(), fracDigits)
d.RestoreFromBound(*s.state)
return d
}
func (s *ReverseCumulativeDeltaCompressor) Renew() {
func (s *CumulativeDeltaCompressor) Renew() {
// УВАГА!
// state не чіпаємо
s.buf = make([]byte, minBufferSize)
@@ -253,13 +253,13 @@ func (s *ReverseCumulativeDeltaCompressor) Renew() {
s.h = 0
}
func (s *ReverseCumulativeDeltaCompressor) Chunks() []byte {
func (s *CumulativeDeltaCompressor) Chunks() []byte {
return s.buf
}
// DECOMPRESSOR
type ReverseCumulativeDeltaDecompressor struct {
type CumulativeDeltaDecompressor struct {
buf []byte
coef float64
pos int
@@ -271,7 +271,7 @@ type ReverseCumulativeDeltaDecompressor struct {
done bool
}
func NewReverseCumulativeDeltaDecompressor(buf []byte, size int, fracDigits byte) *ReverseCumulativeDeltaDecompressor {
func NewCumulativeDeltaDecompressor(buf []byte, size int, fracDigits byte) *CumulativeDeltaDecompressor {
var coef float64 = 1
if fracDigits > 0 {
coef = math.Pow(10, float64(fracDigits))
@@ -281,7 +281,7 @@ func NewReverseCumulativeDeltaDecompressor(buf []byte, size int, fracDigits byte
log.Fatalf("bug: get base value: %s", err)
}
//fmt.Printf("baseValue: %.2f, bound: %d, pos: %d\n", float64(u64)/coef, n, size)
return &ReverseCumulativeDeltaDecompressor{
return &CumulativeDeltaDecompressor{
buf: buf,
coef: coef,
pos: size - 1, // last elem
@@ -290,7 +290,7 @@ func NewReverseCumulativeDeltaDecompressor(buf []byte, size int, fracDigits byte
}
}
func (s *ReverseCumulativeDeltaDecompressor) RestoreFromEnd() {
func (s *CumulativeDeltaDecompressor) RestoreFromEnd() {
if s.pos > s.bound {
// читаю заголовок наступної серії
s.readHeader()
@@ -300,14 +300,14 @@ func (s *ReverseCumulativeDeltaDecompressor) RestoreFromEnd() {
}
}
func (s *ReverseCumulativeDeltaDecompressor) RestoreFromBound(bound CumulativeDeltaBound) {
func (s *CumulativeDeltaDecompressor) RestoreFromBound(bound CumulativeDeltaBound) {
s.pos = bound.Pos - 1
s.lastValue = s.baseValue + float64(bound.LastDelta)
s.decodeHeaderByte(bound.H)
fmt.Printf("restore from bound: isRun=%t, pending=%d\n", s.isRun, s.pending)
}
func (s *ReverseCumulativeDeltaDecompressor) NextValue() (value float64, done bool) {
func (s *CumulativeDeltaDecompressor) NextValue() (value float64, done bool) {
//fmt.Printf("NextValue(): bound: %d, pos: %d, pending: %d\n", s.bound, s.pos, s.pending)
if s.done {
return 0, true
@@ -332,7 +332,7 @@ func (s *ReverseCumulativeDeltaDecompressor) NextValue() (value float64, done bo
return value, false
}
func (s *ReverseCumulativeDeltaDecompressor) readHeader() {
func (s *CumulativeDeltaDecompressor) readHeader() {
h := s.buf[s.pos]
s.pos--
s.decodeHeaderByte(h)
@@ -340,7 +340,7 @@ func (s *ReverseCumulativeDeltaDecompressor) readHeader() {
// fmt.Println("isRun:", s.isRun)
// fmt.Println("pending:", s.pending)
}
func (s *ReverseCumulativeDeltaDecompressor) readValue() {
func (s *CumulativeDeltaDecompressor) readValue() {
u64, n, err := bin.ReverseGetVarUint64(s.buf[:s.pos])
if err != nil {
log.Fatalln(err)
@@ -354,7 +354,7 @@ func (s *ReverseCumulativeDeltaDecompressor) readValue() {
s.lastValue = s.baseValue + float64(u64)/s.coef
}
func (s *ReverseCumulativeDeltaDecompressor) decodeHeaderByte(h byte) {
func (s *CumulativeDeltaDecompressor) decodeHeaderByte(h byte) {
s.isRun = h < 128
if s.isRun {
s.pending = int(h&127) + 2