Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

levenshtein state

Back to all declarations

Distance

func(a string, b string) int

Distance 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)).

Open
OID
04cf6b…8c6a:3
Distance details

Inspect func

Matrix

func(a string, b string) [][]int

Matrix 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).

Open
OID
04cf6b…8c6a:5
Matrix details

Inspect func

Similarity

func(a string, b string) int

Similarity 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.

Open
OID
04cf6b…8c6a:6
Similarity details

Inspect func

renderTable

func(a string, b string) string

renderTable formats the DP matrix as a Markdown table with a and b as headers.

Open
OID
04cf6b…8c6a:8
renderTable details

Inspect func

Render

func(path string) string

Render implements the gnoweb view. - "" or "/" : explanation + examples. - "/\<a>/\<b>" : distance between a and b, with the DP table.

Open
OID
04cf6b…8c6a:9
Render details

Inspect func
Distance : func(a string, b string) int Inspect
Matrix : func(a string, b string) [][]int Inspect
Similarity : func(a string, b string) int Inspect
min3 : func(a int, b int, c int) int Inspect
renderTable : func(a string, b string) string Inspect
Render : func(path string) string Inspect
renderHome : func() string Inspect