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

Function coalesceInterveningIdentical

cmp/report_slices.go:509–527  ·  view source on GitHub ↗

coalesceInterveningIdentical coalesces sufficiently short (<= windowSize) equal groups into adjacent unequal groups that currently result in a dual inserted/removed printout. This acts as a high-pass filter to smooth out high-frequency changes within the windowSize. Example: WindowSize: 16, Inpu

(groups []diffStats, windowSize int)

Source from the content-addressed store, hash-verified

507// {NumIdentical: 63},
508// ]
509func coalesceInterveningIdentical(groups []diffStats, windowSize int) []diffStats {
510 groups, groupsOrig := groups[:0], groups
511 for i, ds := range groupsOrig {
512 if len(groups) >= 2 && ds.NumDiff() > 0 {
513 prev := &groups[len(groups)-2] // Unequal group
514 curr := &groups[len(groups)-1] // Equal group
515 next := &groupsOrig[i] // Unequal group
516 hadX, hadY := prev.NumRemoved > 0, prev.NumInserted > 0
517 hasX, hasY := next.NumRemoved > 0, next.NumInserted > 0
518 if ((hadX || hasX) && (hadY || hasY)) && curr.NumIdentical <= windowSize {
519 *prev = prev.Append(*curr).Append(*next)
520 groups = groups[:len(groups)-1] // Truncate off equal group
521 continue
522 }
523 }
524 groups = append(groups, ds)
525 }
526 return groups
527}
528
529// cleanupSurroundingIdentical scans through all unequal groups, and
530// moves any leading sequence of equal elements to the preceding equal group and

Callers 1

formatDiffSliceMethod · 0.85

Calls 2

NumDiffMethod · 0.80
AppendMethod · 0.80

Tested by

no test coverage detected