You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
1.1 KiB

  1. # levenshtein
  2. levenshtein automaton
  3. This package makes it fast and simple to build a finite determinic automaton that computes the levenshtein distance from a given string.
  4. # Sample usage:
  5. ```
  6. // build a re-usable builder
  7. lb := NewLevenshteinAutomatonBuilder(2, false)
  8. origTerm := "couchbasefts"
  9. dfa := lb.BuildDfa("couchbases", 2)
  10. ed := dfa.eval([]byte(origTerm))
  11. if ed.distance() != 2 {
  12. log.Errorf("expected distance 2, actual: %d", ed.distance())
  13. }
  14. ```
  15. This implementation is inspired by [blog post](https://fulmicoton.com/posts/levenshtein/) and is intended to be
  16. a port of original rust implementation: https://github.com/tantivy-search/levenshtein-automata
  17. Micro Benchmark Results against the current vellum/levenshtein is as below.
  18. ```
  19. BenchmarkNewEditDistance1-8 30000 52684 ns/op 89985 B/op 295 allocs/op
  20. BenchmarkOlderEditDistance1-8 10000 132931 ns/op 588892 B/op 363 allocs/op
  21. BenchmarkNewEditDistance2-8 10000 199127 ns/op 377532 B/op 1019 allocs/op
  22. BenchmarkOlderEditDistance2-8 2000 988109 ns/op 4236609 B/op 1898 allocs/op
  23. ```