MCPcopy
hub / github.com/google/go-cmp / coalesceAdjacentEdits

Function coalesceAdjacentEdits

cmp/report_slices.go:453–475  ·  view source on GitHub ↗

coalesceAdjacentEdits coalesces the list of edits into groups of adjacent equal or unequal counts. Example: Input: "..XXY...Y" Output: [ {NumIdentical: 2}, {NumRemoved: 2, NumInserted 1}, {NumIdentical: 3}, {NumInserted: 1}, ]

(name string, es diff.EditScript)

Source from the content-addressed store, hash-verified

451// {NumInserted: 1},
452// ]
453func coalesceAdjacentEdits(name string, es diff.EditScript) (groups []diffStats) {
454 var prevMode byte
455 lastStats := func(mode byte) *diffStats {
456 if prevMode != mode {
457 groups = append(groups, diffStats{Name: name})
458 prevMode = mode
459 }
460 return &groups[len(groups)-1]
461 }
462 for _, e := range es {
463 switch e {
464 case diff.Identity:
465 lastStats('=').NumIdentical++
466 case diff.UniqueX:
467 lastStats('!').NumRemoved++
468 case diff.UniqueY:
469 lastStats('!').NumInserted++
470 case diff.Modified:
471 lastStats('!').NumModified++
472 }
473 }
474 return groups
475}
476
477// coalesceInterveningIdentical coalesces sufficiently short (<= windowSize)
478// equal groups into adjacent unequal groups that currently result in a

Callers 1

formatDiffSliceMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected