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 package

Overview

Package levenshtein ports the classic Levenshtein edit-distance algorithm (as found in Go libraries like agext/levenshtein) to a gno.land realm.

The core is the textbook dynamic-programming matrix: the minimum number of single-character insertions, deletions, or substitutions to turn string a into string b. It is fully rune-aware and pure (deterministic), so it runs happily on-chain.

Functions

Distance

func Distance(a, 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)).

Params

Command

gnokey query vm/qeval -remote "https://rpc.topaz.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/levenshtein.Distance(,)"

Result

Matrix

func Matrix(a, 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).

Params

Command

gnokey query vm/qeval -remote "https://rpc.topaz.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/levenshtein.Matrix(,)"

Result

Render

func Render(path string) string

Render implements the gnoweb view.

  • "" or "/" : explanation + examples.
  • "/<a>/<b>" : distance between a and b, with the DP table.

Param

Command

gnokey query vm/qeval -remote "https://rpc.topaz.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/levenshtein.Render()"

Result

Similarity

func Similarity(a, 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.

Params

Command

gnokey query vm/qeval -remote "https://rpc.topaz.testnets.gno.land" -data "gno.land/r/g12cs4cehujpffpjpywmkqj43m6u5ya53nj69sjz/levenshtein.Similarity(,)"

Result