MCPcopy Create free account
hub / github.com/databus23/helm-diff / calculateDistances

Function calculateDistances

diff/diff.go:534–566  ·  view source on GitHub ↗

Calculate distance of every diff-line to the closest change

(diffs []difflib.DiffRecord)

Source from the content-addressed store, hash-verified

532
533// Calculate distance of every diff-line to the closest change
534func calculateDistances(diffs []difflib.DiffRecord) map[int]int {
535 distances := map[int]int{}
536
537 // Iterate forwards through diffs, set 'distance' based on closest 'change' before this line
538 change := -1
539 for i, diff := range diffs {
540 if diff.Delta != difflib.Common {
541 change = i
542 }
543 distance := math.MaxInt32
544 if change != -1 {
545 distance = i - change
546 }
547 distances[i] = distance
548 }
549
550 // Iterate backwards through diffs, reduce 'distance' based on closest 'change' after this line
551 change = -1
552 for i := len(diffs) - 1; i >= 0; i-- {
553 diff := diffs[i]
554 if diff.Delta != difflib.Common {
555 change = i
556 }
557 if change != -1 {
558 distance := change - i
559 if distance < distances[i] {
560 distances[i] = distance
561 }
562 }
563 }
564
565 return distances
566}
567
568// reIndexForRelease based on template names
569func reIndexForRelease(index map[string]*manifest.MappingResult) map[string]*manifest.MappingResult {

Callers 1

printDiffRecordsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected