diff options
author | n-peugnet <n.peugnet@free.fr> | 2021-09-23 12:03:50 +0200 |
---|---|---|
committer | n-peugnet <n.peugnet@free.fr> | 2021-09-23 12:03:50 +0200 |
commit | c47d2184b2e6a1e7dbd139ca47bb3aebcfeb754f (patch) | |
tree | 251a99c8bfbececaf797dde8629d7f43334cb210 /slice/slice.go | |
parent | 03e3d1aa9eb6e6917d2a9e6b85f7dd6f92e20d04 (diff) | |
download | dna-backup-c47d2184b2e6a1e7dbd139ca47bb3aebcfeb754f.tar.gz dna-backup-c47d2184b2e6a1e7dbd139ca47bb3aebcfeb754f.zip |
add String to Delta struct and use it in logs
Also switch to external package for slice_test as it was already a case
of "black box testing".
Diffstat (limited to 'slice/slice.go')
-rw-r--r-- | slice/slice.go | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/slice/slice.go b/slice/slice.go index 05441c8..e5b959e 100644 --- a/slice/slice.go +++ b/slice/slice.go @@ -1,6 +1,9 @@ package slice -import "reflect" +import ( + "fmt" + "reflect" +) type Slice []interface{} @@ -11,11 +14,24 @@ type Ins struct { Value []interface{} } +type insData struct { + idx int + count int +} + type Delta struct { Del []Del Ins []Ins } +func (d Delta) String() string { + data := make([]insData, len(d.Ins)) + for i, ins := range d.Ins { + data[i] = insData{ins.Idx, len(ins.Value)} + } + return fmt.Sprintf("{Del: %d Ins: %+v}", d.Del, data) +} + func Patch(source Slice, delta Delta) (target Slice) { // apply Del part from patch to source into temp size := len(source) - len(delta.Del) |