Skip to content

Commit 64e471d

Browse files
committed
add byte delta
1 parent e943aca commit 64e471d

File tree

4 files changed

+53
-2
lines changed

4 files changed

+53
-2
lines changed

byte.go

+24
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,26 @@
11
package delta
22

3+
// ByteSliceDelta 字节数组
4+
func ByteSliceDelta(bytes []byte) []byte {
5+
result := make([]byte, 0)
6+
for index, value := range bytes {
7+
if index == 0 {
8+
result[index] = value
9+
} else {
10+
result[index] = bytes[index-1] - value
11+
}
12+
}
13+
return result
14+
}
15+
16+
func ByteSliceFromDelta(bytes []byte) []byte {
17+
result := make([]byte, 0)
18+
for index, value := range bytes {
19+
if index == 0 {
20+
result[index] = value
21+
} else {
22+
result[index] = result[index-1] + value
23+
}
24+
}
25+
return result
26+
}

go.mod

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ module github.com/compression-algorithm-research-lab/go-delta
22

33
go 1.18
44

5-
require github.com/golang-infrastructure/go-gtypes v0.0.1 // indirect
5+
require (
6+
github.com/golang-infrastructure/go-gtypes v0.0.1 // indirect
7+
github.com/golang-infrastructure/go-heap v0.0.2 // indirect
8+
github.com/golang-infrastructure/go-queue v0.0.0-20221128180429-701892f44bcc // indirect
9+
)

go.sum

+4
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
github.com/golang-infrastructure/go-gtypes v0.0.1 h1:hnM1OYSwLPLGkZ4C6ecAxgmAUaPTjnhnUtRNmJj4p6c=
22
github.com/golang-infrastructure/go-gtypes v0.0.1/go.mod h1:vFMCxFzxdMInvTtgLZRlWI1rS+mui88sMbL5I+zu1hg=
3+
github.com/golang-infrastructure/go-heap v0.0.2 h1:o3u5Wr8W/MO2PjtczBOEwb7HdUgK5zV12aAdp7T28IA=
4+
github.com/golang-infrastructure/go-heap v0.0.2/go.mod h1:crBY8pM89fprjRYrEGalpJ7xEzhD+XtxiFAuF9JnCuM=
5+
github.com/golang-infrastructure/go-queue v0.0.0-20221128180429-701892f44bcc h1:+i4Y16ygfCIRKnEfwSd7cfQ+KvSMx/ALePIf8wTFRuc=
6+
github.com/golang-infrastructure/go-queue v0.0.0-20221128180429-701892f44bcc/go.mod h1:Ype8CrMpjePHOJq+wRoIN3hx10H/WQsZ5SNvHdiSsBQ=

struct.go

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
package delta
22

3+
import (
4+
"reflect"
5+
)
6+
37
// ZipStructSlice 对Struct序列进行压缩
4-
func ZipStructSlice() {
8+
func ZipStructSlice[T any](slice []T) {
9+
10+
}
11+
12+
func diff[T any](a, b T) *StructDelta {
13+
reflectA := reflect.ValueOf(a)
14+
reflectB := reflect.ValueOf(b)
15+
16+
switch reflectA.Type().Kind() {
17+
case reflect.String:
18+
19+
}
520
}
621

722
type StructDelta struct {
23+
Init any
24+
FieldDeltaMap map[string]*FieldDelta
825
}
926

1027
type FieldDelta struct {
28+
FieldName string
29+
FieldValue string
1130
}

0 commit comments

Comments
 (0)