MCPcopy Create free account
hub / github.com/cli/cli / editDistance

Function editDistance

script/ghmock/schemacmd.go:665–683  ·  view source on GitHub ↗
(a, b string)

Source from the content-addressed store, hash-verified

663}
664
665func editDistance(a, b string) int {
666 prev := make([]int, len(b)+1)
667 cur := make([]int, len(b)+1)
668 for j := range prev {
669 prev[j] = j
670 }
671 for i := 1; i <= len(a); i++ {
672 cur[0] = i
673 for j := 1; j <= len(b); j++ {
674 cost := 1
675 if a[i-1] == b[j-1] {
676 cost = 0
677 }
678 cur[j] = min(prev[j]+1, cur[j-1]+1, prev[j-1]+cost)
679 }
680 prev, cur = cur, prev
681 }
682 return prev[len(b)]
683}
684
685// cmdSchemas runs ghmock schemas update, which downloads both schema files
686// again, to the files ghmock uses.

Callers 1

closeMatchesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected