diff options
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) |