Skip to content

Commit e943aca

Browse files
committed
add int
1 parent 7c2464f commit e943aca

File tree

8 files changed

+71
-2
lines changed

8 files changed

+71
-2
lines changed

Diff for: README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#
1+
#
22

33

44

Diff for: byte.go

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
package delta
2+

Diff for: go.mod

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
module 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

Diff for: go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
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=

Diff for: int.go

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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+
}

Diff for: int_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

Diff for: string.go

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package delta
2+
3+
4+

Diff for: struct.go

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package delta
2+
3+
// ZipStructSlice 对Struct序列进行压缩
4+
func ZipStructSlice() {
5+
}
6+
7+
type StructDelta struct {
8+
}
9+
10+
type FieldDelta struct {
11+
}

0 commit comments

Comments
 (0)