{"id":49524363,"url":"https://github.com/atomflunder/ldist","last_synced_at":"2026-05-02T02:01:02.653Z","repository":{"id":355124392,"uuid":"1226879984","full_name":"atomflunder/ldist","owner":"atomflunder","description":"A Go implementation of a Levenshtein distance based string matching algorithm. ","archived":false,"fork":false,"pushed_at":"2026-05-02T00:02:57.000Z","size":8,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-05-02T01:23:33.660Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/atomflunder.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-05-01T23:43:38.000Z","updated_at":"2026-05-02T00:08:48.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/atomflunder/ldist","commit_stats":null,"previous_names":["atomflunder/ldist"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/atomflunder/ldist","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomflunder%2Fldist","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomflunder%2Fldist/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomflunder%2Fldist/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomflunder%2Fldist/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/atomflunder","download_url":"https://codeload.github.com/atomflunder/ldist/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/atomflunder%2Fldist/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32520156,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-02T01:12:54.858Z","status":"online","status_checked_at":"2026-05-02T02:00:05.923Z","response_time":132,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2026-05-02T02:01:01.704Z","updated_at":"2026-05-02T02:01:02.583Z","avatar_url":"https://github.com/atomflunder.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ldist\n[![Go Reference](https://pkg.go.dev/badge/github.com/atomflunder/ldist.svg)](https://pkg.go.dev/github.com/atomflunder/ldist) [![Test / CI](https://github.com/atomflunder/ldist/actions/workflows/ci.yml/badge.svg)](https://github.com/atomflunder/ldist/actions/workflows/ci.yml) [![codecov](https://codecov.io/gh/atomflunder/ldist/graph/badge.svg?token=ONLF7D1OBG)](https://codecov.io/gh/atomflunder/ldist)\n\nA Go implementation of a Levenshtein distance based string matching algorithm. Designed to be easy, fast and flexible to use with no dependencies.\n\n## Installation\n\n```bash\ngo get github.com/atomflunder/ldist\n```\n\n## Usage\n\n### Basic Usage\n\nYou can calculate the Levenshtein distance between two strings using the `Distance` function.  \nBy default, it uses the standard weights for substitution, insertion, and deletion.\n\n```go\nimport (\n    \"fmt\"\n    \"github.com/atomflunder/ldist\"\n)\n\ns1 := \"kitten\"\ns2 := \"  SITTING  \"\n\n// Gets you the default weights for the Levenshtein algorithm.\n// The default weights are: Substitution: 1, Insertion: 1, Deletion: 1.\nw := ldist.GetWeights()\n\ndist := ldist.Distance(s1, s2, w)\nfmt.Printf(\"Normal Distance: %d\\n\", dist)\n// Output: Normal Distance: 11\n```\n\n### Custom Weights\n\nYou can also specify custom weights for the Levenshtein algorithm by creating a `Weights` struct and passing it to the `Distance` function.  \nThis allows you to assign different costs to substitutions, insertions, and deletions.\n\n```go\nimport (\n    \"fmt\"\n    \"github.com/atomflunder/ldist\"\n)\n\ns1 := \"kitten\"\ns2 := \"  SITTING  \"\n\n// Create custom weights for the Levenshtein algorithm.\nw := ldist.Weights{\n    Substitution: 3,\n    Insertion: 1,\n    Deletion: 2,\n}\n\ndist := ldist.Distance(s1, s2, w)\nfmt.Printf(\"Custom Distance: %d\\n\", dist)\n// Output: Custom Distance: 23\n```\n\n### With Options\n\nYou can also specify some options for pre-processing the strings before calculating the distance.  \nFor example, you can choose to ignore case and whitespace.\n\n```go\nimport (\n    \"fmt\"\n    \"github.com/atomflunder/ldist\"\n)\n\ns1 := \"kitten\"\ns2 := \"  SITTING  \"\n\nw := ldist.GetWeights()\n\n// Uses the ToLowercase and RemoveWhitespace options to pre-process the strings before calculating the distance.\n// This would convert \"  SITTING  \" into \"sitting\".\ndist := ldist.Distance(s1, s2, weights, ldist.ToLowercase, ldist.RemoveWhitespace)\n\nfmt.Printf(\"Distance with Options: %d\\n\", dist)\n// Output: Distance with Options: 3\n```\n\n### Normalized Functions\n\nThe package also provides normalized versions of the distance and similarity functions, which return values between 0 and 1 based on the maximum possible distance for the given strings.\n\n```go\nimport (\n    \"fmt\"\n    \"github.com/atomflunder/ldist\"\n)\n\ns1 := \"kitten\"\ns2 := \"  SITTING  \"\n\nw := ldist.GetWeights()\n\n// A normalized distance of 0 means the strings are identical, while a normalized distance of 1 means they are completely different.\n// The normalized distance is calculated as the actual distance divided by the maximum possible distance for the given strings.\nnormalizedDist := ldist.NormalizedDistance(s1, s2, w, ldist.ToLowercase, ldist.RemoveWhitespace)\n\n// A normalized similarity of 1 means the strings are identical, while a normalized similarity of 0 means they are completely different.\n// The normalized similarity is calculated as 1 - normalized distance.\nnormalizedSim := ldist.NormalizedSimilarity(s1, s2, w, ldist.ToLowercase, ldist.RemoveWhitespace)\n\nfmt.Printf(\"Normalized Distance: %.2f\\n\", normalizedDist)\nfmt.Printf(\"Normalized Similarity: %.2f\\n\", normalizedSim)\n// Output:\n// Normalized Distance: 0.18\n// Normalized Similarity: 0.82\n```\n\n## API Reference\n\nCan be found in the [GoDoc](https://pkg.go.dev/github.com/atomflunder/ldist).\n\n## Testing \u0026 Coverage\n\nYou can run the tests using the following command:\n\n```bash\ngo test -v\n```\n\nCheck the code coverage with:\n\n```bash\ngo test -coverprofile -cover.out .\ngo tool cover -html cover.out -o cover.html\n```\n\n## Performance \u0026 Benchmarks\n\nYou can run the benchmarks with:\n\n```bash\ngo test -bench=.\n```\n\nResults (on my machine):\n\n```bash\nBenchmarkDistance-32                \t11266522\t        95.96 ns/op\nBenchmarkNormalizedDistance-32      \t12367748\t        96.25 ns/op\nBenchmarkNormalizedSimilarity-32    \t12120586\t        98.67 ns/op\nBenchmarkLongStrings-32             \t  988434\t      1214 ns/op\n```\n\n## Contributing\n\nContributions are welcome! If you have any ideas for improvements or new features, please feel free to open an issue or submit a pull request.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomflunder%2Fldist","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fatomflunder%2Fldist","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fatomflunder%2Fldist/lists"}