Reduce regular graph construction memory and support NFAs - #234
Open
zayenz wants to merge 5 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The regular propagator builds a layered graph for the sequence and automaton. The old initializer reserves a state slot for every automaton state at every sequence position, requiring (n + 1)k temporary
Stateobjects even when few are reachable.This change constructs sparse forward frontiers, filters them by backward co-reachability, and allocates persistent states after the surviving layer sizes are known. State-related construction memory is O(k + S), where S is the number of states in the final layered graph. For an unfolded DFA, S <= k. A looping automaton can still have S = Theta(nk), but construction no longer adds a second dense state matrix. The persistent
Layer,Support,Edge, andStaterepresentation is unchanged.DFA::nfa(start, transitions, finals)explicitly constructs an epsilon-free NFA, retaining nondeterministic transitions without determinization or minimization. Array and initializer-list overloads are available. Ordinary DFA constructors retain their deterministic-transition precondition. Cloning only removes assigned prefix layers with a single edge, preserving branching NFA paths and their edge counts.Tests cover cyclic frontiers, acyclic reconvergence, position-specific pruning, failed acceptance, Boolean views, terminal merging, state-index boundaries, randomized DFA/NFA differential checks, and assigned NFA prefixes during cloning. The NFA differential and prefix cases are included in both CMake and Autoconf check selections.
Validation:
Existing Apple Clang Release measurements for sparse construction, not repeated for the NFA addition:
The Windows vcpkg checkout and manifest baseline are aligned to the same pinned commit, replacing a GMP portfile that requested a removed MSYS2 autoconf archive.