Skip to content

Text indelpattern distance

github-actions[bot] edited this page Sep 24, 2026 · 4 revisions

Development build. This page describes main, not a released package. The latest published Lodestar.Text is 0.7.0 — read its documentation.

HomeTextDistances

IndelPattern.Distance

The Indel distance between the held pattern and a text.

public int Distance(ReadOnlySpan<char> text)

Parameterstext is the string to scan against the pattern.

Returns — the fewest insertions and deletions that turn one into the other, the number Indel.Distance gives for the same pair over UTF-16 units.

ExceptionsObjectDisposedException when the handle has been disposed.

Example — the same answer as the pairwise call, with the table built once.

using Lodestar.Text.Distances;

using IndelPattern query = IndelPattern.For("kitten");

int held = query.Distance("sitting".AsSpan());          // => 5
int pairwise = Indel.Distance("kitten", "sitting");     // => 5

Remarks — a substitution costs two here as it does everywhere in Indel: this counts insertions and deletions, never replacements.

Scanning is thread-safe — the table is only read — but disposal is not, so do not dispose a handle another thread is still scanning with.

Applies to — net10.0, netstandard2.0.

See alsoIndelPattern, Indel.Distance, IndelPattern.NormalizedSimilarity.

Clone this wiki locally