Table of Contents

Public classStatic LevenshteinDistance

Namespace
Rowles.LeanLucene.Search
Assembly
Rowles.LeanLucene.dll

Computes Levenshtein edit distance between two strings or UTF-8 byte spans. Uses a single-row DP approach with stackalloc for short strings.

public static class LevenshteinDistance
LevenshteinDistance

Public method Compute(ReadOnlySpan<char>, ReadOnlySpan<char>)

Computes the Levenshtein edit distance between two character spans.

Public method ComputeAscii(ReadOnlySpan<byte>, ReadOnlySpan<byte>)

Computes Levenshtein edit distance on raw byte spans. Only valid for ASCII text where each byte is one character. Returns -1 if either span contains multi-byte UTF-8 sequences (high bit set).

Public method ComputeAsciiBounded(ReadOnlySpan<byte>, ReadOnlySpan<byte>, int)

Bounded ASCII Levenshtein: returns the edit distance if ≤ maxEdits, otherwise returns maxEdits + 1. Returns -1 if either span contains non-ASCII bytes.

Public method ComputeBounded(ReadOnlySpan<char>, ReadOnlySpan<char>, int)

Bounded Levenshtein: returns the edit distance if ≤ maxEdits, otherwise returns maxEdits + 1. Early-terminates rows where the minimum value exceeds the threshold.