Skip to content

Text 0.7.0 indelpattern for

github-actions[bot] edited this page Sep 24, 2026 · 1 revision

Lodestar.Text 0.7.0. This page is frozen at that release. Read the current documentation for what main says now. A link to a decision or a migration page follows main, and leaves the archive.

Home › Distances

IndelPattern.For

Builds a handle over a pattern, renting the equality table every later scan reads.

public static IndelPattern For(string pattern)
public static IndelPattern For(ReadOnlySpan<char> pattern)

Parameters — pattern is the one side every scan compares against.

Returns — an IndelPattern to dispose once the last text has been scanned.

Exceptions — ArgumentNullException when pattern is null.

Example — one query against a list, the table built once.

using Lodestar.Text.Distances;

string[] candidates = ["kitten", "sitting", "mitten", "bitten"];
using IndelPattern query = IndelPattern.For("kitten");

double best = candidates.Max(c => query.NormalizedSimilarity(c.AsSpan()));   // => 1
int worst = candidates.Max(c => query.Distance(c.AsSpan()));                 // => 5

Remarks — the span overload copies, because a handle outlives the call that built it and a ReadOnlySpan<char> cannot be held. Hand it a string where you have one and no copy is made.

The table is rented from ArrayPool<ulong>, so a handle that is never disposed leaks nothing but does force the pool to allocate a replacement. A using statement is the intended shape.

Building a handle for a single comparison is a loss: Indel.Distance takes two strings and does not have to fill a table that outlives the call.

Applies to — net10.0, netstandard2.0.

See also — IndelPattern, Indel, IndelPattern.Dispose.

Clone this wiki locally