Distance
func(a string, b string) intDistance returns the Levenshtein edit distance between a and b. It counts single-rune insertions, deletions, and substitutions and works on runes (not bytes), so multi-byte UTF-8 input is handled correctly. The classic two-row DP is used, so memory is O(min(len)) and time is O(len(a)\*len(b)).
- OID
- 04cf6b…8c6a:3
Distance details
Matrix
func(a string, b string) [][]intMatrix returns the full (len(a)+1) x (len(b)+1) DP matrix used by Distance. matrix\[i]\[j] is the edit distance between the first i runes of a and the first j runes of b. The bottom-right cell equals Distance(a, b).
- OID
- 04cf6b…8c6a:5
Matrix details
Similarity
func(a string, b string) intSimilarity returns a 0..100 percentage of how similar a and b are, defined as (1 - distance/maxLen) \* 100 rounded to the nearest integer. Two empty strings are considered 100% similar.
- OID
- 04cf6b…8c6a:6
Similarity details
min3
func(a int, b int, c int) int- OID
- 04cf6b…8c6a:7
min3 details
renderTable
func(a string, b string) stringrenderTable formats the DP matrix as a Markdown table with a and b as headers.
- OID
- 04cf6b…8c6a:8
renderTable details
Render
func(path string) stringRender implements the gnoweb view. - "" or "/" : explanation + examples. - "/\<a>/\<b>" : distance between a and b, with the DP table.
- OID
- 04cf6b…8c6a:9
Render details
renderHome
func() string- OID
- 04cf6b…8c6a:10