Section navigation

Public classSealed FstReader

Namespace
Rowles.LeanCorpus.Codecs.Fst
Assembly
Rowles.LeanCorpus.dll

Reads a minimal acyclic FST serialised by FstBuilder (FST1 format).

Provides arc-walk lookup (O(key length)), prefix enumeration (DFS over shared-prefix sub-graphs), and intersection with an arbitrary IAutomaton for prefix, wildcard, and Levenshtein queries — all without materialising the full key set.

The serialised blob layout is the one documented on FstBuilder:

[magic "FST1" 4B][rootAddress VarInt][keyCount VarInt][node data...]

Arc addresses produced by the builder are offsets into the node-data section (the bytes following the header), not into the whole blob. The reader keeps the node section in _nodes so addresses index it directly.

public sealed class FstReader
Inheritance
FstReader

Public property Count

Number of keys stored in the FST.

Public property IsEmpty

True when the FST has no keys.

Public method CollectContainsOutputs(ReadOnlySpan<byte>, ReadOnlySpan<byte>, List<long>)

Collects outputs for keys starting with qualifier whose suffix contains needle (UTF-8 byte-wise). Allocation-light: reuses a single key buffer and emits offsets directly into sink.

Public method CollectIntersectOutputs(IAutomaton, ReadOnlySpan<byte>, List<long>)

Collects all outputs whose key matches automaton when applied to the suffix following qualifier, appending to sink. Allocation-light: no iterator state-machine or per-arc copying.

Public method CollectOutputsWithPrefix(ReadOnlySpan<byte>, List<long>)

Collects all outputs whose key starts with prefix, appending to sink. Allocation-light: no iterator state-machine.

Public method EnumerateAll()

Enumerates all (key, output) pairs in sorted byte order.

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

Returns the outputs for every key starting with qualifier whose suffix contains needle (UTF-8 byte-wise substring match). The key is kept in a reusable buffer and never materialised as an array.

Public method EnumerateOutputsWithPrefix(ReadOnlySpan<byte>)

Outputs-only enumeration of all outputs whose key starts with prefix. Does not materialise any keys.

Public method EnumerateWithPrefix(ReadOnlySpan<byte>)

Enumerates all (key, output) pairs whose key starts with prefix, in sorted byte order.

Public method IntersectAutomaton(IAutomaton)

Intersects the FST with an automaton, returning matching (key, output, finalState) triples. Both the automaton and the FST consume the same byte sequence; pruning is driven by CanMatch(int). The automaton is fed every byte of every key (callers wishing to skip a leading qualifier should construct a PrefixAutomaton over the qualifier and compose it with their target automaton, or use the qualifier overload).

Public method IntersectAutomaton(IAutomaton, ReadOnlySpan<byte>)

Intersects the FST with an automaton applied to the bytes following qualifier. Only keys starting with the qualifier are considered; the automaton sees the bare suffix.

Public method IntersectAutomatonOutputs(IAutomaton, ReadOnlySpan<byte>)

Outputs-only variant of IntersectAutomaton(IAutomaton, ReadOnlySpan<byte>). Avoids materialising the matched key, suitable for offset-only query paths.

Public method Open(byte[])

Open an FST from a complete serialised blob produced by Finish().

Public method TryGetOutput(ReadOnlySpan<byte>, out long)

Walks the FST for an exact key match. Returns true and the summed output along the accept path (real arcs plus the optional final-output virtual arc) when found.