mikemccand commented on code in PR #13714: URL: https://github.com/apache/lucene/pull/13714#discussion_r1743958059
########## lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java: ########## @@ -182,26 +182,44 @@ public static Automaton repeat(Automaton a) { // Repeating the empty automata will still only accept the empty automata. return a; } + + if (a.isAccept(0) && a.getAcceptStates().nextSetBit(1) == -1) { Review Comment: I guess it is allowed to pass `1` to `nextSetBit` even if the `BitSet` is length 1? Javadoc seems to say it only throws `IndexOutOfBoundsException` if you pass a negative index, and the example `for` loop would do what you are doing here on a length 1 `BitSet` so I think it's OK. ########## lucene/core/src/java/org/apache/lucene/util/automaton/Operations.java: ########## @@ -182,26 +182,44 @@ public static Automaton repeat(Automaton a) { // Repeating the empty automata will still only accept the empty automata. return a; } + + if (a.isAccept(0) && a.getAcceptStates().nextSetBit(1) == -1) { + // If the only accept state is 0, then this automaton already repeats itself. Automata + // returned by this function only accept state 0, so this makes this function idempotent. + return a; Review Comment: This is quite a cool observation (both sentences, separately)! Maybe swap the words `only accept` to make it more accurate (`only` is referring to `state 0`, not really `accept`). Proper `only` placement is tricky! -- 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: issues-unsubscr...@lucene.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@lucene.apache.org For additional commands, e-mail: issues-h...@lucene.apache.org