Levenshtypo 1.6.0

dotnet add package Levenshtypo --version 1.6.0
                    
NuGet\Install-Package Levenshtypo -Version 1.6.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Levenshtypo" Version="1.6.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Levenshtypo" Version="1.6.0" />
                    
Directory.Packages.props
<PackageReference Include="Levenshtypo" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Levenshtypo --version 1.6.0
                    
#r "nuget: Levenshtypo, 1.6.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=Levenshtypo&version=1.6.0
                    
Install Levenshtypo as a Cake Addin
#tool nuget:?package=Levenshtypo&version=1.6.0
                    
Install Levenshtypo as a Cake Tool

๐Ÿ” Levenshtypo

Fast, typo-tolerant string lookup for your .NET apps โ€“ powered by Levenshtein Automata + Trie magic.

Levenshtypo is a high-performance fuzzy matching library that helps you find strings even when your users mistype them. Whether you're building search, suggestions, command matchers, or text correction tools, Levenshtypo lets you query massive datasets with typo tolerance and blazingly fast response times.


๐Ÿš€ Features

  • โšก๏ธ Fast fuzzy lookup over large datasets
  • ๐Ÿ“š Backed by a Trie for fast prefix traversal
  • ๐Ÿง  Uses Levenshtein Distance for string matching
  • ๐ŸŽฏ Also supports restricted edit distance (insertions, deletions, substitutions + transpositions)
  • ๐Ÿ—๏ธ Fully exposed Levenshtein Automata for custom workflows
  • ๐Ÿงช Minimal allocations and branchy hot paths tuned for speed

๐Ÿ’ก Why Use Levenshtypo?

Traditional string matching fails when:

  • Your users make typos ("git cmomit")
  • Input comes from noisy sources (voice input, OCR)
  • You want a UX that feels smart, not frustrating

Instead of dictionary["cmomit"] you can do leveshtrie.Search("cmomit", maxEditDistance: 1).


๐Ÿงช Basic Usage

using Levenshtypo;

var matcher = Levenshtrie.CreateStrings(["docker", "doctor", "rocket", "locker"]);

foreach (var match in matcher.Search("docer", 2))
{
    Console.WriteLine($"{match.Result} (distance {match.Distance})");
}

// docker(distance 1)
// doctor(distance 2)
// locker(distance 2)

๐Ÿง  Under the Hood

  • The dataset is loaded into a Trie.
  • A Levenshtein automaton is built on the fly from your query.
  • The trie is traversed with the automaton to prune irrelevant branches early, yielding matches quickly.

๐Ÿ”จ Installation

๐Ÿ“ฆ Available on NuGet:

Install-Package Levenshtypo

Or via CLI:

dotnet add package Levenshtypo

Automated Tests

AOT Compatible


โš™๏ธ Automaton-Only Mode

Need raw speed and full control?

var automaton = LevenshtomatonFactory.Instance.Construct(
        "docker",
        maxEditDistance: 2,
        metric: LevenshtypoMetric.RestrictedEdit);

foreach (var word in english)
{
    if (automaton.Matches(word))
    {
        Console.WriteLine(word);
    }
}

โ˜๏ธ Over 3000x faster than using if(LevenshteinDistance(word, "docker") <= 2)

You can hook into the automaton layer directly for:

  • Custom indexing
  • Building autocomplete engines
  • Approximate dictionary search

๐Ÿง  Performance

Levenshtypo is written with performance at the forefront of all decisions.

Practical Example: Matching against 450,000+ words (Edit Distance = 1) is typically less than 0.02 ms compared to 73 ms with a for-loop.

If the following benchmarks don't impress you, nothing will!

<details> <summary>Search all English Language with a fuzzy key</summary>

  • Naive: Compute Levenshtein Distance against all words.
  • Levenshtypo_All: This library, with all results buffered into an array.
  • Levenshtypo_Lazy: This library, with lazy evaluation (IEnumerable).
  • Levenshtypo_Any: This library, with lazy evaluation (IEnumerable), stopping at the first result.
  • Dictionary: .NET Dictionary which only works for distance of 0.
Method Mean Allocated
Distance0_Levenshtypo_All 361.444 ns 240 B
Distance0_Levenshtypo_Lazy 975.169 ns 480 B
Distance0_Levenshtypo_Any 614.947 ns 480 B
Distance0_Dictionary 9.128 ns -
Distance0_Naive 813,419.616 ns 89 B
Distance1_Levenshtypo_All 19,008.096 ns 536 B
Distance1_Levenshtypo_Lazy 38,615.868 ns 480 B
Distance1_Levenshtypo_Any 25,805.258 ns 480 B
Distance1_Naive 73,459,775.661 ns 193 B
Distance2_Levenshtypo_All 276,157.020 ns 2600 B
Distance2_Levenshtypo_Lazy 440,689.397 ns 480 B
Distance2_Levenshtypo_Any 215,542.244 ns 480 B
Distance2_Naive 68,999,745.833 ns 700 B
Distance3_Levenshtypo_All 1,617,282.340 ns 25985 B
Distance3_Levenshtypo_Lazy 2,452,026.901 ns 1123 B
Distance3_Levenshtypo_Any 231,972.804 ns 584 B
Distance3_Naive 71,845,738.624 ns 4369 B

</details>

<details> <summary>Load all English Language dataset</summary>

  • Levenshtypo: This library.
  • Dictionary: .NET Dictionary for comparison.
Method Mean Allocated
English_Dictionary 31,755.45 ฮผs 35524.19 KB
English_Levenshtypo 142,010.47 ฮผs 145145.15 KB

</details>


๐Ÿ“– License

MIT โ€” free for personal and commercial use.


Made with โค๏ธ, performance profiling, and typo tolerance by @andrewjsaid

Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net6.0

    • No dependencies.
  • net8.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.6.0 54 5/10/2025
1.5.0 134 5/1/2025
1.4.0 33,915 8/21/2024
1.3.0 8,216 8/12/2024
1.2.0 122 8/9/2024
1.1.0 80 8/2/2024
1.0.0 75 7/31/2024