Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 15 additions & 10 deletions src/main/java/org/eu/autogex/algorithms/Minimizer.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,25 @@ private static Map<BehaviorSignature, Set<State>> splitGroup(
// Maps the behavioral "signature" of a state to the subgroup of states sharing it
Map<BehaviorSignature, Set<State>> subGroups = new HashMap<>();

// Optimization: Hoist map lookup and array length out of the loop
Map<State, Map<Character, State>> transitionTable = dfa.getTransitionTable();
int alphabetLen = alphabetArray.length;

for (State s : group) {
// The signature is: "For each character, which partition do I end up in?"
int[] targets = new int[alphabetArray.length];
Map<Character, State> transitions = dfa.getTransitionTable().get(s);
int[] targets = new int[alphabetLen];
Map<Character, State> transitions = transitionTable.get(s);

for (int i = 0; i < alphabetArray.length; i++) {
if (transitions == null) {
targets[i] = -1;
continue;
// Optimization: Unswitch condition for trap states and use fast array fill
if (transitions == null) {
Arrays.fill(targets, -1);
} else {
for (int i = 0; i < alphabetLen; i++) {
State destination = transitions.get(alphabetArray[i]);
Integer targetPartitionId =
destination != null ? stateToPartitionId.get(destination) : null;
targets[i] = targetPartitionId != null ? targetPartitionId : -1;
}
State destination = transitions.get(alphabetArray[i]);
Integer targetPartitionId =
destination != null ? stateToPartitionId.get(destination) : null;
targets[i] = targetPartitionId != null ? targetPartitionId : -1;
}
BehaviorSignature behaviorSignature = new BehaviorSignature(targets);

Expand Down