AC自动机
1.根据字符构造trie树 2.构建失败匹配指针 1.根节点的所以一代子孩子失败指针都指向root 2.子节点匹配失败时,找到父节点的失败指针,找不到就一直找,直到找到root还匹配不到,直接指向root 3.文本串匹配 1.如果已经匹配到完整的模式串,根据失败指针切换线路继续向下查找 2.如果还没有匹配完,那么就向下匹配 class ACNode { constructor(data){ this.data = data this.children = new Map() this.isEndingChar = false this.length = 0 this.fail = null } } class ACTree { constructor(){ this.root = new ACNode('/') } insert(text){ let node = this.root for(let char of text){ if(!node.children.get(char)){ node.children.set(char,new ACNode(char)) } node = node.children.get(char) } node.isEndingChar = true node.length = text.length } buildFailurePointer(