Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Operations#union merge accept states that have no outgoing transition. #14207

Merged
merged 3 commits into from
Feb 10, 2025

Conversation

jpountz
Copy link
Contributor

@jpountz jpountz commented Feb 6, 2025

This helps generate simpler automata, especially when these automata are later combined through other operations such as Operations#concat.

…ition.

This helps generate simpler automata, especially when these automata are later
combined through other operations such as `Operations#concat`.
@@ -1052,6 +1052,77 @@ public static Automaton removeDeadStates(Automaton a) {
return result;
}

/** Merge all accept states that don't have outgoing transitions to a single shared state. */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, couldn't we potentially use this for other operations such as reverse() which might cause the same inefficiency as union() today?

Can we hit it with a simple random test for good feelings about it?

for (int i = 0; i < N; i++) {
  Automaton expected = AutomatonTestUtil.randomAutomata(random);
  Automaton actual = mergeAcceptStates(expected);
  assertSameLanguage(expected, actual);
}

Copy link
Member

@rmuir rmuir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for tackling this!

@jpountz jpountz merged commit 3208920 into apache:main Feb 10, 2025
6 checks passed
@jpountz jpountz deleted the union_merge_accept_states branch February 10, 2025 21:55
jpountz added a commit that referenced this pull request Feb 10, 2025
…ition. (#14207)

This helps generate simpler automata, especially when these automata are later
combined through other operations such as `Operations#concat`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants