Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Basic DFA snippet
struct BasicDFA {
typedef u8 State;
u8 transitions[16][256];
State start_state;
BasicDFA(std::vector<std::tuple<u32, u32, u8>> & trans_vec, u8 start_state_, u8 default_state) {
...
}
State apply(const u8 * data, size_t len, State s) {
size_t i = 0;
for (; i+7 < len; i+=8) {
u8 c1 = data[i+0];
...
u8 c8 = data[i+7];
s = transitions[s][c1];
...
s = transitions[s][c8];
}
for (; i < len; ++i) {
s = transitions[s][data[i]];
}
return s;
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.