-
Notifications
You must be signed in to change notification settings - Fork 0
Text indelpattern for
Development build. This page describes
main, not a released package. The latest published Lodestar.Text is 0.6.0 — read its documentation.
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())); // => 5Remarks — 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.