(self)
| 40 | self.adlist[current_state]["output"].append(keyword) |
| 41 | |
| 42 | def set_fail_transitions(self) -> None: |
| 43 | q: deque = deque() |
| 44 | for node in self.adlist[0]["next_states"]: |
| 45 | q.append(node) |
| 46 | self.adlist[node]["fail_state"] = 0 |
| 47 | while q: |
| 48 | r = q.popleft() |
| 49 | for child in self.adlist[r]["next_states"]: |
| 50 | q.append(child) |
| 51 | state = self.adlist[r]["fail_state"] |
| 52 | while ( |
| 53 | self.find_next_state(state, self.adlist[child]["value"]) is None |
| 54 | and state != 0 |
| 55 | ): |
| 56 | state = self.adlist[state]["fail_state"] |
| 57 | self.adlist[child]["fail_state"] = self.find_next_state( |
| 58 | state, self.adlist[child]["value"] |
| 59 | ) |
| 60 | if self.adlist[child]["fail_state"] is None: |
| 61 | self.adlist[child]["fail_state"] = 0 |
| 62 | self.adlist[child]["output"] = ( |
| 63 | self.adlist[child]["output"] |
| 64 | + self.adlist[self.adlist[child]["fail_state"]]["output"] |
| 65 | ) |
| 66 | |
| 67 | def search_in(self, string: str) -> dict[str, list[int]]: |
| 68 | """ |
no test coverage detected