Go implementations for the Levenshtein Distance.
There are existing packages that implement Levenshtein Distance, I have created this package for learning.
Implementations:
- Full Matrix - the Wagner-Fischer algorithm for computing the Levenshtein Distance, which utilizes dynamic programing.
- Two Rows - an optimization for the Wagner-Fischer algorithm, which takes only two matrix rows regardless of the input. this is the most performant implementation in this package.
- Recursive - the original implementaion. an inefficient implementation, created for learning purposes.
When using this package, you should use the Distance
- alias for the Two Rows implementaion.
Using this package:
go get github.com/rotemhoresh/levenshtein
d := levenshtein.Distance("kitten", "sitting")
fmt.Printf("edit distance between 'kitten' and 'sitting' is %d", d)
// Output:
// edit distance between 'kitten' and 'sitting' is 3
Test and Benchmark fucntions are available for all implementations.
# test
go test
# benchmark
go test -bench=. -benchmem
MIT