Skip to content

Optimize transition lookup in CompiledAutomaton.addTail using binary search #16360

Description

@rajat315315

Description

Description:

Description

In CompiledAutomaton.java within the addTail method, a linear scan $O(N)$ is currently used to find the largest transition index where the transition's minimum label is less than the leadLabel:

    // Find biggest transition that's < label
    // TODO: use binary search here
    int maxIndex = -1;
    int numTransitions = automaton.initTransition(state, transition);
    for (int i = 0; i < numTransitions; i++) {
      automaton.getNextTransition(transition);
      if (transition.min < leadLabel) {
        maxIndex = i;
      } else {
        // Transitions are always sorted
        break;
      }
    }

Since the automaton transitions are always sorted by minimum label first, we can optimize this transition lookup to run in $O(\log N)$ time by implementing a binary search using random access (automaton.getTransition(state, index, transition)).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions