git-bug/vendor/github.com/agnivade/levenshtein
2018-09-14 12:41:59 +02:00
..
.gitignore graphql: update gqlgen to 0.5.1 2018-09-14 12:41:59 +02:00
.travis.yml graphql: update gqlgen to 0.5.1 2018-09-14 12:41:59 +02:00
go.mod graphql: update gqlgen to 0.5.1 2018-09-14 12:41:59 +02:00
levenshtein.go graphql: update gqlgen to 0.5.1 2018-09-14 12:41:59 +02:00
License.txt graphql: update gqlgen to 0.5.1 2018-09-14 12:41:59 +02:00
Makefile graphql: update gqlgen to 0.5.1 2018-09-14 12:41:59 +02:00
README.md graphql: update gqlgen to 0.5.1 2018-09-14 12:41:59 +02:00

levenshtein Build Status Go Report Card GoDoc

Go package to calculate the Levenshtein Distance

The library is fully capable of working with non-ascii strings. But the strings are not normalized. That is left as a user-dependant use case. Please normalize the strings before passing it to the library if you have such a requirement.

Install

go get github.com/agnivade/levenshtein

Example

package main

import (
	"fmt"
	"github.com/agnivade/levenshtein"
)

func main() {
	s1 := "kitten"
	s2 := "sitting"
	distance := levenshtein.ComputeDistance(s1, s2)
	fmt.Printf("The distance between %s and %s is %d.\n", s1, s2, distance)
	// Output:
	// The distance between kitten and sitting is 3.
}

Benchmarks

name              time/op
Simple/ASCII-4     537ns ± 2%
Simple/French-4    956ns ± 0%
Simple/Nordic-4   1.95µs ± 1%
Simple/Tibetan-4  1.53µs ± 2%

name              alloc/op
Simple/ASCII-4     96.0B ± 0%
Simple/French-4     128B ± 0%
Simple/Nordic-4     192B ± 0%
Simple/Tibetan-4    144B ± 0%

name              allocs/op
Simple/ASCII-4      1.00 ± 0%
Simple/French-4     1.00 ± 0%
Simple/Nordic-4     1.00 ± 0%
Simple/Tibetan-4    1.00 ± 0%