File tree Expand file tree Collapse file tree 8 files changed +71
-2
lines changed Expand file tree Collapse file tree 8 files changed +71
-2
lines changed Original file line number Diff line number Diff line change 1- #
1+ #
22
33
44
Original file line number Diff line number Diff line change 1+ package delta
2+
Original file line number Diff line number Diff line change 11module github.com/compression-algorithm-research-lab/go-delta
22
3- go 1.19
3+ go 1.18
4+
5+ require github.com/golang-infrastructure/go-gtypes v0.0.1 // indirect
Original file line number Diff line number Diff line change 1+ github.com/golang-infrastructure/go-gtypes v0.0.1 h1:hnM1OYSwLPLGkZ4C6ecAxgmAUaPTjnhnUtRNmJj4p6c =
2+ github.com/golang-infrastructure/go-gtypes v0.0.1 /go.mod h1:vFMCxFzxdMInvTtgLZRlWI1rS+mui88sMbL5I+zu1hg =
Original file line number Diff line number Diff line change 1+ package delta
2+
3+ import "github.com/golang-infrastructure/go-gtypes"
4+
5+ // ZipIntegerSlice delta压缩整数,只适合正整数一般
6+ func ZipIntegerSlice [T gtypes.Integer ](intSlice []T ) []T {
7+ result := make ([]T , len (intSlice ))
8+ for index , x := range intSlice {
9+ if index == 0 {
10+ result [index ] = x
11+ continue
12+ }
13+ delta := intSlice [index - 1 ] - intSlice [index ]
14+ result [index ] = delta
15+ }
16+ return result
17+ }
18+
19+ // UnzipIntegerSlice 解压缩delta
20+ func UnzipIntegerSlice [T gtypes.Integer ](intSlice []T ) []T {
21+ result := make ([]T , len (intSlice ))
22+ for index , x := range intSlice {
23+ if index == 0 {
24+ result [index ] = x
25+ continue
26+ }
27+ delta := result [index - 1 ] - intSlice [index ]
28+ result [index ] = delta
29+ }
30+ return result
31+ }
Original file line number Diff line number Diff line change 1+ package delta
2+
3+ import (
4+ "testing"
5+ )
6+
7+ func TestUnzipIntegerSlice (t * testing.T ) {
8+ slice := make ([]int , 0 )
9+ for i := 0 ; i < 100 ; i ++ {
10+ slice = append (slice , 10000 - i * 10 )
11+ }
12+ t1 := ZipIntegerSlice (slice )
13+ t .Log (t1 )
14+
15+ t2 := UnzipIntegerSlice (t1 )
16+ t .Log (t2 )
17+ }
Original file line number Diff line number Diff line change 1+ package delta
2+
3+
4+
Original file line number Diff line number Diff line change 1+ package delta
2+
3+ // ZipStructSlice 对Struct序列进行压缩
4+ func ZipStructSlice () {
5+ }
6+
7+ type StructDelta struct {
8+ }
9+
10+ type FieldDelta struct {
11+ }
You can’t perform that action at this time.
0 commit comments