BuildExtendedAc Functions that builds extended Aho Corasick automaton.
(p []string)
| 44 | |
| 45 | // BuildExtendedAc Functions that builds extended Aho Corasick automaton. |
| 46 | func BuildExtendedAc(p []string) (acToReturn map[int]map[uint8]int, f map[int][]int) { |
| 47 | acTrie, stateIsTerminal, f := ConstructTrie(p) |
| 48 | s := make([]int, len(stateIsTerminal)) //supply function |
| 49 | i := 0 //root of acTrie |
| 50 | acToReturn = acTrie |
| 51 | s[i] = -1 |
| 52 | for current := 1; current < len(stateIsTerminal); current++ { |
| 53 | o, parent := GetParent(current, acTrie) |
| 54 | down := s[parent] |
| 55 | for StateExists(down, acToReturn) && GetTransition(down, o, acToReturn) == -1 { |
| 56 | down = s[down] |
| 57 | } |
| 58 | if StateExists(down, acToReturn) { |
| 59 | s[current] = GetTransition(down, o, acToReturn) |
| 60 | if stateIsTerminal[s[current]] { |
| 61 | stateIsTerminal[current] = true |
| 62 | f[current] = ArrayUnion(f[current], f[s[current]]) //F(Current) <- F(Current) union F(S(Current)) |
| 63 | } |
| 64 | } else { |
| 65 | s[current] = i //initial state? |
| 66 | } |
| 67 | } |
| 68 | a := ComputeAlphabet(p) // concat of all patterns in p |
| 69 | for j := range a { |
| 70 | if GetTransition(i, a[j], acToReturn) == -1 { |
| 71 | CreateTransition(i, a[j], i, acToReturn) |
| 72 | } |
| 73 | } |
| 74 | for current := 1; current < len(stateIsTerminal); current++ { |
| 75 | for j := range a { |
| 76 | if GetTransition(current, a[j], acToReturn) == -1 { |
| 77 | CreateTransition(current, a[j], GetTransition(s[current], a[j], acToReturn), acToReturn) |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | return acToReturn, f |
| 82 | } |
no test coverage detected