uschindler commented on code in PR #12286:
URL: https://github.com/apache/lucene/pull/12286#discussion_r1192986099


##########
lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java:
##########
@@ -34,6 +34,7 @@
 import java.util.Arrays;
 import java.util.BitSet;
 import java.util.Collection;
+import java.util.Deque;

Review Comment:
   Import not needed (see below).



##########
lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java:
##########
@@ -1303,24 +1308,49 @@ public static int[] topoSortStates(Automaton a) {
     return states;
   }
 
-  // TODO: not great that this is recursive... in theory a
-  // large automata could exceed java's stack so the maximum level of 
recursion is bounded to 1000
-  private static int topoSortStatesRecurse(
-      Automaton a, BitSet visited, int[] states, int upto, int state, int 
level) {
-    if (level > MAX_RECURSION_LEVEL) {
-      throw new IllegalArgumentException("input automaton is too large: " + 
level);
-    }
+  /**
+   * Performs a topological sort on the states of the given Automaton.
+   *
+   * @param a The automaton whose states are to be topologically sorted.
+   * @param states An int array which stores the states.
+   * @return the reversed topologically sorted array of state ids
+   * @throws IllegalArgumentException if the input automaton has a cycle.
+   */
+  private static int topoSortStates(Automaton a, int[] states) {
+    BitSet onStack = new BitSet(a.getNumStates());
+    BitSet visited = new BitSet(a.getNumStates());
+    Deque<Integer> stack = new ArrayDeque<>();

Review Comment:
   Use `var` declaration or just do it in the same way like anywhere else in 
this file (there are multiple usages of `ArrayDeque`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to