MCPcopy Create free account
hub / github.com/driangle/taskmd / levenshtein

Function levenshtein

apps/cli/internal/cli/get.go:305–332  ·  view source on GitHub ↗

levenshtein computes the edit distance between two strings.

(a, b string)

Source from the content-addressed store, hash-verified

303
304// levenshtein computes the edit distance between two strings.
305func levenshtein(a, b string) int {
306 la, lb := len(a), len(b)
307 if la == 0 {
308 return lb
309 }
310 if lb == 0 {
311 return la
312 }
313
314 prev := make([]int, lb+1)
315 for j := range prev {
316 prev[j] = j
317 }
318
319 for i := 1; i <= la; i++ {
320 curr := make([]int, lb+1)
321 curr[0] = i
322 for j := 1; j <= lb; j++ {
323 cost := 1
324 if a[i-1] == b[j-1] {
325 cost = 0
326 }
327 curr[j] = min(curr[j-1]+1, min(prev[j]+1, prev[j-1]+cost))
328 }
329 prev = curr
330 }
331 return prev[lb]
332}
333
334// promptSelection displays fuzzy matches and asks the user to pick one.
335func promptSelection(query string, matches []fuzzyMatch) (*model.Task, error) {

Callers 3

TestLevenshteinFunction · 0.85
suggestValueFunction · 0.85
calculateSimilarityFunction · 0.85

Calls

no outgoing calls

Tested by 1

TestLevenshteinFunction · 0.68