MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / search

Method search

AhoCorasick.java:56–73  ·  view source on GitHub ↗
(String text)

Source from the content-addressed store, hash-verified

54
55 // Step 3: Search the Text
56 public List<String> search(String text) {
57 List<String> results = new ArrayList<>();
58 TrieNode currentNode = root;
59
60 for (char c : text.toCharArray()) {
61 while (currentNode != root && !currentNode.children.containsKey(c)) {
62 currentNode = currentNode.failureLink;
63 }
64 if (currentNode.children.containsKey(c)) {
65 currentNode = currentNode.children.get(c);
66 }
67
68 // Add matches to results
69 results.addAll(currentNode.output);
70 }
71
72 return results;
73 }
74
75 public static void main(String[] args) {
76 AhoCorasick ac = new AhoCorasick();

Callers 1

mainMethod · 0.95

Calls 1

getMethod · 0.45

Tested by

no test coverage detected