Last active
February 1, 2018 05:13
-
-
Save pervognsen/bed78438279114e402cfd932cde32bd0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Thompson's algorithm for NFA execution. | |
// Each NFA state is numbered 0 through n-1. | |
// An n-bit vector represents a superposition of NFA states, called a superstate. | |
// A state has a superstate as its successor, as a function of the input symbol. | |
// This induces a superstate-to-superstate successor mapping: | |
for (next_superstate = 0, successor = successors[symbol]; superstate; superstate >>= 1, successor++) | |
next_superstate |= *successor & -(superstate & 1); | |
// Run this, starting with an initial superstate, for each symbol of the input string. | |
// The final superstate is accepting if any of its states are accepting. This algorithm | |
// runs in O(m n) time, where m is the length of the input string. The space required for | |
// the state successor table is O(k n log(n)) words for a k-symbol alphabet, likely k = 256. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment