Skip to content
Merged
Show file tree
Hide file tree
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
28 changes: 28 additions & 0 deletions src/main/java/org/eu/autogex/models/DFA.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,34 @@ private DFA(Builder builder) {
this.transitionTable = Map.copyOf(builder.transitionTable);
}

/**
* Fast-path evaluation of an input string bypassing ExecutionTrace generation. Overrides the
* default method to minimize memory allocation and maximize performance.
*
* @param input The string to be evaluated.
* @return true if the string is accepted, false otherwise.
*/
@Override
public boolean accepts(String input) {
State currentState = initialState;

for (int i = 0; i < input.length(); i++) {
char symbol = input.charAt(i);
Map<Character, State> stateTransitions = transitionTable.get(currentState);

if (stateTransitions == null) {
return false;
}

currentState = stateTransitions.get(symbol);
if (currentState == null) {
return false;
}
}

return finalStates.contains(currentState);
}

@Override
public ExecutionTrace execute(String input) {
List<ExecutionStep> steps = new ArrayList<>();
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/org/eu/autogex/models/ENFA.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,31 @@ public Set<State> epsilonClosure(Set<State> startStates) {
return closure;
}

/**
* Fast-path evaluation of an input string bypassing ExecutionTrace generation. Overrides the
* default method to minimize memory allocation and maximize performance.
*
* @param input The string to be evaluated.
* @return true if the string is accepted, false otherwise.
*/
@Override
public boolean accepts(String input) {
Set<State> currentStates = epsilonClosure(Set.of(initialState));

for (int i = 0; i < input.length(); i++) {
char symbol = input.charAt(i);

Set<State> moveResult = computeNextStates(currentStates, symbol, transitionTable);
currentStates = epsilonClosure(moveResult);

if (currentStates.isEmpty()) {
return false;
}
}

return !Collections.disjoint(currentStates, finalStates);
}

@Override
public ExecutionTrace execute(String input) {
List<ExecutionStep> steps = new ArrayList<>();
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/org/eu/autogex/models/NFA.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,30 @@ private NFA(Builder builder) {
this.transitionTable = Map.copyOf(builder.transitionTable);
}

/**
* Fast-path evaluation of an input string bypassing ExecutionTrace generation. Overrides the
* default method to minimize memory allocation and maximize performance.
*
* @param input The string to be evaluated.
* @return true if the string is accepted, false otherwise.
*/
@Override
public boolean accepts(String input) {
Set<State> currentStates = Set.of(initialState);

for (int i = 0; i < input.length(); i++) {
char symbol = input.charAt(i);

currentStates = computeNextStates(currentStates, symbol, transitionTable);

if (currentStates.isEmpty()) {
return false;
}
}

return !Collections.disjoint(currentStates, finalStates);
}

@Override
public ExecutionTrace execute(String input) {
List<ExecutionStep> steps = new ArrayList<>();
Expand Down