Created
December 6, 2012 03:36
-
-
Save v2e4lisp/4221607 to your computer and use it in GitHub Desktop.
javascript string match automata. (tobefixed)
This file contains hidden or 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
var string_automata = function (string) { | |
var length = string.length; | |
var init = string[0]; | |
var automata = []; | |
automata[0][init] = [1]; | |
// var get_state_by_id = function (id) { | |
// return automata[id]; | |
// } | |
var update_next_state = function (input, cur_id) { | |
if (cur_id === length) { | |
return true; | |
} | |
var cur_state = automata[cur_id]; | |
var next_list = []; | |
if (!cur_state[input]) { | |
return [0]; | |
} | |
cur_state[input].forEach (function (i) { | |
if (automata[i][input]) { | |
next_list.concat (automata[i][input]); | |
} | |
}); | |
if (input === init) { | |
next_list.push(1) | |
} | |
next_list.push(cur_id+2); | |
automata[cur_id+1][input] = new_list; | |
return false | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment