TokenSortMatch 0.2.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package TokenSortMatch --version 0.2.0
                    
NuGet\Install-Package TokenSortMatch -Version 0.2.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="TokenSortMatch" Version="0.2.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TokenSortMatch" Version="0.2.0" />
                    
Directory.Packages.props
<PackageReference Include="TokenSortMatch" />
                    
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 TokenSortMatch --version 0.2.0
                    
#r "nuget: TokenSortMatch, 0.2.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.
#:package TokenSortMatch@0.2.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TokenSortMatch&version=0.2.0
                    
Install as a Cake Addin
#tool nuget:?package=TokenSortMatch&version=0.2.0
                    
Install as a Cake Tool

TokenSortMatch

Fast token-sort fuzzy best-matching for .NET. Zero dependencies.

Scores are bit-identical to Fuzz.Ratio(normalize(a), normalize(b)) from RapidFuzz/FuzzySharp (token-sort ratio with full preprocessing) — verified by a randomized oracle test suite — while batch matching runs ~7-9× faster than RapidFuzz's native cdist on short items (~6.5× on long ones) and ~1 000× faster than per-pair FuzzySharp, under plain AVX2 (benchmarks), via:

  • transposed pattern bitmasks + bit-parallel LCS (Hyyrö/Myers) in length-bucketed 16/32/64-bit lanes — 16, 8 or 4 items per Vector256 pass (auto opt-in; scalar fallback for CPUs without 256-bit SIMD),
  • allocation-free query normalization (char-map table, in-place token sort),
  • exactly-rounded score upper bounds pruning item groups against the running best,
  • 4-lane vectorized multi-block path (per-lane carry/borrow chains) for items whose normalized form exceeds 64 chars.

Usage

using TokenSortMatch;

// Pairwise
int score = TokenSort.Ratio("Лекционные занятия", "занятия ЛЕКЦИОННЫЕ!"); // 100
string norm = TokenSort.Normalize("The-Quick! Brown?? fox"); // "brown fox quick the"

// Batch: build an index over candidate items once, query many times
var index = new TokenSortIndex(["Лекционные занятия", "Практические занятия", "Экзамен"]);

BestMatch? best = index.FindBest("занятия лекционные 5", threshold: 80);
// -> BestMatch(ItemIndex: 0, Score: 87)

int[] scores = index.FindBestScores(queries, threshold: 80);      // parallel, -1 if below
BestMatch?[] all = index.FindBestMatches(queries, threshold: 80); // parallel, null if below

Semantics:

  • Normalize: lowercase letters/digits, everything else → spaces, tokens sorted ordinally, joined with single spaces (same per-char behavior as StringPreprocessor.Full / RapidFuzz default_process).
  • Score: round(100 · (1 − indelDistance / (len1 + len2))) with banker's rounding; empty normalized strings score 0.
  • FindBest*: thresholds ≤ 0 always match (scores are non-negative); ties return one deterministic best-scoring item. TokenSortIndex is immutable and thread-safe.

License

MIT

Product Compatible and additional computed target framework versions.
.NET 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 is compatible.  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 is compatible.  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.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.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
0.3.0 122 10/31/2026
0.2.0 133 9/23/2026
0.1.0 158 7/9/2026