class Sz API
ClassSzCore StringZilla operations: search, compare, hash, and memory primitives.42
SegmentKindA tiling segmentation: every byte lands in exactly one segment.
NormalFormUnicode normalization forms, NfkcCasefold being NFKC with full case folding and without default-ignorable codepoints, the Unicode toNFKC_Casefold that caseless keys match on.
IndexOfFirst byte offset of needle in haystack , or -1.
long IndexOf(ReadOnlySpan<byte> haystack, ReadOnlySpan<byte> needle); long IndexOf(ReadOnlySpan<byte> haystack, byte needle); Like IndexOf(ReadOnlySpan<byte>, ReadOnlySpan<byte>), for a single byte: the first offset of needle , or -1.
Like System.MemoryExtensions.IndexOf<T>(System.ReadOnlySpan<T>,System.ReadOnlySpan<T>), SIMD-accelerated for large inputs. Keywords: find, search, substring, indexof.
LastIndexOfLike IndexOf(ReadOnlySpan<byte>, ReadOnlySpan<byte>) from the end: the last byte offset of needle , or -1.
long LastIndexOf(
ReadOnlySpan<byte> haystack,
ReadOnlySpan<byte> needle); long LastIndexOf(ReadOnlySpan<byte> haystack, byte needle); Like LastIndexOf(ReadOnlySpan<byte>, ReadOnlySpan<byte>), for a single byte: the last offset of needle , or -1.
IndexOfAnyFirst offset of any byte present in set , or -1.
long IndexOfAny(ReadOnlySpan<byte> haystack, ref Byteset set); LastIndexOfAnyLast offset of any byte present in set , or -1.
long LastIndexOfAny(ReadOnlySpan<byte> haystack, ref Byteset set); EqualByte-wise equality.
bool Equal(ReadOnlySpan<byte> a, ReadOnlySpan<byte> b); Like System.MemoryExtensions.SequenceEqual<T>(System.ReadOnlySpan<T>,System.ReadOnlySpan<T>).
CompareLexicographic byte comparison: -1, 0, or 1.
int Compare(ReadOnlySpan<byte> a, ReadOnlySpan<byte> b); Like System.MemoryExtensions.SequenceCompareTo<T>(System.ReadOnlySpan<T>,System.ReadOnlySpan<T>).
HashFast 64-bit AES-based hash (SMHasher-quality), with optional seed .
ulong Hash(ReadOnlySpan<byte> data, ulong seed = 0); Unlike string.GetHashCode(), this is stable across runs/processes and identical across all StringZilla bindings. For cryptographic hashing use Sha256.
ByteSumSum of all byte values in data as an unsigned 64-bit integer.
ulong ByteSum(ReadOnlySpan<byte> data); CountRunesCounts Unicode scalar values (codepoints) in UTF-8 text .
long CountRunes(ReadOnlySpan<byte> text); Like counting System.Text.Runes, but SIMD-accelerated over UTF-8 bytes with no UTF-16 transcode. Keywords: codepoint, rune count, length.
CountRunes("你好世界"u8) is 4; CountRunes("Hello🌍"u8) is 6 — the astral emoji is a single scalar.
SeekRuneByte offset of the index -th codepoint (0-based), or -1 if fewer exist.
long SeekRune(ReadOnlySpan<byte> text, long index); Analogous to string.EnumerateRunes positioning, on UTF-8 bytes.
DecodeDecodes UTF-8 codepoints into destination (one Int32 scalar each; ill-formed or truncated sequences become U+FFFD).
int Decode(ReadOnlySpan<byte> text, Span<int> destination); int Decode(
ReadOnlySpan<byte> text,
Span<int> destination,
out long bytesConsumed); As Decode(System.ReadOnlySpan<byte>,System.Span<int>), also reporting how many input bytes were consumed so callers can resume.
Returns the count written, stopping early only when destination fills.
Like System.Text.Rune.DecodeFromUtf8 in bulk, SIMD-accelerated. Emitted values are valid Unicode scalars (incl. U+FFFD): wrap with new Rune(cp).
DecodeAllAllocates and returns all codepoints of text as Int32 scalars.
int[] DecodeAll(ReadOnlySpan<byte> text); SegmentWrites the byte lengths of the next segments of text into the caller's lengths and returns the count written.
int Segment(
ReadOnlySpan<byte> text,
SegmentKind kind,
Span<long> lengths); Allocation-free. Segments tile the text, each starting where the previous one ended, so resume at the sum of the lengths; only an empty text yields 0.
Graphemes ≈ System.Globalization.StringInfo / System.Globalization.TextElementEnumerator; words/sentences/lines follow UAX-29 / UAX-14. SIMD-accelerated, deterministic, over UTF-8 bytes (no locale, no transcode). Keywords: grapheme, word break, sentence, line break, TextElement, BreakIterator.
Segmentation tiles the text — every byte lands in exactly one segment. By SegmentKind.Graphemes, the flag 🇺🇸 is one cluster spanning two codepoints and "e"+U+0301 (a decomposed é) is one cluster spanning two; by SegmentKind.Words, "Hello, 世界" splits the Latin run from the CJK run.
CaseFoldFolds into the caller's destination (must hold ≥ text.Length*3 bytes) and returns the bytes written.
int CaseFold(ReadOnlySpan<byte> text, Span<byte> destination); byte[] CaseFold(ReadOnlySpan<byte> text); Full Unicode case folding (UAX #21, one-to-many, e.g.
Allocation-free.
UncasedIndexOfCase-insensitive (full-fold) search: byte offset of the first match, or -1; sets matchedLength (may differ from needle length due to folding).
long UncasedIndexOf(
ReadOnlySpan<byte> haystack,
ReadOnlySpan<byte> needle,
out long matchedLength); Fills a gap: no .NET caseless UTF-8 substring search. For repeated searches with the same needle, prefer UncasedNeedle.
UncasedCompareCase-insensitive (full-fold) lexicographic comparison: -1, 0, or 1.
int UncasedCompare(ReadOnlySpan<byte> a, ReadOnlySpan<byte> b); Fills a gap: no .NET Unicode case-folded ordinal comparison.
HashMultiseedHashes data under each seed, writing results into hashes (must hold ≥ seeds.Length entries).
void HashMultiseed(
ReadOnlySpan<byte> data,
ReadOnlySpan<ulong> seeds,
Span<ulong> hashes); ulong[] HashMultiseed(
ReadOnlySpan<byte> data,
ReadOnlySpan<ulong> seeds); Allocating convenience: returns a fresh array of one hash per seed.
Allocation-free.
FillRandomFills buffer with deterministic pseudo-random bytes derived from nonce (AES-CTR-style; reproducible for the same nonce).
void FillRandom(Span<byte> buffer, ulong nonce); LookupByte-wise table transform: destination[i] = lut[source[i]].
void Lookup(
Span<byte> destination,
ReadOnlySpan<byte> source,
ReadOnlySpan<byte> lut); lut must be exactly 256 bytes.
NormalizeNormalizes into the caller's destination (must hold ≥ text.Length*18 bytes) and returns the bytes written.
int Normalize(
ReadOnlySpan<byte> text,
NormalForm form,
Span<byte> destination); byte[] Normalize(ReadOnlySpan<byte> text, NormalForm form); Normalizes UTF-8 text to the given form.
Allocation-free.
IsNormalizedTrue if text is already in the given normalization form.
bool IsNormalized(ReadOnlySpan<byte> text, NormalForm form); Equivalent to string.IsNormalized(System.Text.NormalizationForm).
ArgSortWrites the sorting permutation of items into order (must hold ≥ items.Count entries) and returns the count of sorted indices (top if > 0, else items.Count).
int ArgSort(
IReadOnlyList<byte[]> items,
Span<long> order,
bool reverse = false,
long top = 0,
bool uncased = false); long[] ArgSort(
IReadOnlyList<byte[]> items,
bool reverse = false,
long top = 0,
bool uncased = false); Allocating convenience: returns a fresh permutation array.
int ArgSort(
ReadOnlySpan<byte> text,
ReadOnlySpan<long> starts,
ReadOnlySpan<long> lengths,
Span<long> order,
bool reverse = false,
long top = 0,
bool uncased = false); Sorts the segments of a single buffer in place — given per-segment starts and lengths (as produced by the split iterators), writes their sorting permutation into order and returns the count.
Allocation-free for the result.
Like System.Array.Sort(System.Array) with System.StringComparer.Ordinal, but returns indices and runs over UTF-8 bytes.
IntersectInner-joins two de-duplicated sequences, writing matching index pairs into firstPositions / secondPositions (each must hold ≥ min(a.Count, b.Count) entries) and returns the match count.
int Intersect(
IReadOnlyList<byte[]> a,
IReadOnlyList<byte[]> b,
Span<long> firstPositions,
Span<long> secondPositions,
ulong seed = 0); Allocation-free for the result.
EnumerateRunesLazily enumerates the Unicode codepoints of text as System.Text.Runes (ill-formed sequences yield U+FFFD).
RuneEnumerable EnumerateRunes(ReadOnlySpan<byte> text); Like string.EnumerateRunes, over UTF-8 bytes; batches 64 per native call. Allocation-free; synchronous foreach only (the enumerator is a ref struct).
EnumerateWordsLazily enumerates UAX-29 word segments as byte-slice views (tiling; no empty segments).
SegmentEnumerable EnumerateWords(ReadOnlySpan<byte> text); Like iterating System.Globalization.StringInfo word elements, but over UTF-8 bytes.
EnumerateGraphemesLazily enumerates UAX-29 grapheme clusters as byte-slice views (tiling).
SegmentEnumerable EnumerateGraphemes(ReadOnlySpan<byte> text); Like System.Globalization.StringInfo.GetTextElementEnumerator(string), over UTF-8 bytes.
EnumerateSentencesLazily enumerates UAX-29 sentences as byte-slice views (tiling).
SegmentEnumerable EnumerateSentences(ReadOnlySpan<byte> text); EnumerateLineBreaksLazily enumerates UAX-14 line-break units as byte-slice views (tiling).
SegmentEnumerable EnumerateLineBreaks(ReadOnlySpan<byte> text); SplitLazily splits text on each occurrence of separator , yielding the segments between separators as byte-slice views.
SplitEnumerable Split(
ReadOnlySpan<byte> text,
ReadOnlySpan<byte> separator); Empty segments are kept by default (like string.Split(string[],System.StringSplitOptions)); chain .SkipEmpty(), .KeepSeparator(), or .WithMaxSplit(n) to change behaviour.
RSplitAs Split but scanning from the end; yields the last segment first.
SplitEnumerable RSplit(
ReadOnlySpan<byte> text,
ReadOnlySpan<byte> separator); SplitAnyLazily splits on any byte in separators (like splitting on a character set).
SplitEnumerable SplitAny(ReadOnlySpan<byte> text, Byteset separators); RSplitAnyAs SplitAny but scanning from the end.
SplitEnumerable RSplitAny(ReadOnlySpan<byte> text, Byteset separators); EnumerateMatchesLazily enumerates the byte offsets of every (non-overlapping) match of needle in haystack ; chain .Overlapping() for overlaps.
MatchEnumerable EnumerateMatches(
ReadOnlySpan<byte> haystack,
ReadOnlySpan<byte> needle); Counting the result is the occurrence count. An empty needle matches at every offset, the end included.
SplitNewlinesLazily splits on Unicode newline runs, yielding the lines between them.
TokenSplitEnumerable SplitNewlines(ReadOnlySpan<byte> text); Chain .WithSeparators() for a lossless interleave or .SkipEmpty() to drop blanks.
SplitWhitespacesLazily splits on Unicode whitespace runs, yielding the fields between them.
TokenSplitEnumerable SplitWhitespaces(ReadOnlySpan<byte> text); SplitDelimitersLazily splits on Unicode delimiter runs (punctuation/symbols/separators).
TokenSplitEnumerable SplitDelimiters(ReadOnlySpan<byte> text); EnumerateUncasedMatchesLazily enumerates case-insensitive (full-fold) matches of needle , yielding each match's offset and matched length (which may differ from the needle length due to folding, e.g.
UncasedMatchEnumerable EnumerateUncasedMatches(
ReadOnlySpan<byte> haystack,
ReadOnlySpan<byte> needle); "ß" matching "SS"). Chain .Overlapping() for overlapping matches. An empty needle matches at every codepoint boundary, the end included.
PartitionSplits at the first occurrence of separator into (before, separator, after) views; if absent, returns (text , empty, empty).
Partition Partition(
ReadOnlySpan<byte> text,
ReadOnlySpan<byte> separator); RPartitionAs Partition but at the last occurrence; if absent, returns (empty, empty, text ).
Partition RPartition(
ReadOnlySpan<byte> text,
ReadOnlySpan<byte> separator); CapabilitiesNameNames the capabilities in capabilities , comma-separated, like "serial,haswell".
string CapabilitiesName(ulong capabilities); StructBytesetA 256-bit set of byte values.5
struct Byteset AddAdds value to the set.
void Add(byte value); AddRangeAdds every byte of values to the set.
void AddRange(ReadOnlySpan<byte> values); ContainsReturns true if value is in the set.
bool Contains(byte value); InvertReplaces the set with its complement, so members become non-members and the reverse.
void Invert(); FromBytesCreates a set holding every byte of values .
Byteset FromBytes(ReadOnlySpan<byte> values);