Skip to content

Commit

Permalink
Fix bug in TrieTree.java
Browse files Browse the repository at this point in the history
  • Loading branch information
frost-lotus committed Jul 21, 2022
1 parent ef28a8b commit b90f34d
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions dexlib2/src/main/java/org/jf/util/TrieTree.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,23 @@ public TrieNode nextNode(char content) {
}

public void add(String word) {
if (word == null)
return;

TrieNode current = root;
StringBuilder wordBuilder = new StringBuilder();

char content;
TrieNode node;
for (int index = 0; index < word.length(); ++index) {
char content = word.charAt(index);
content = word.charAt(index);
wordBuilder.append(content);
TrieNode node = new TrieNode(content, wordBuilder.toString());
node = new TrieNode(content, wordBuilder.toString());
if (current.children.contains(node)) {
current = current.nextNode(content);
} else {
if (index == word.length() - 1)
node.isEnd = true;
current.children.add(node);
current = node;
}
Expand All @@ -66,9 +74,14 @@ public void addAll(List<String> words) {
}

public boolean search(String word) {
if (word == null)
return false;

TrieNode current = root;

char content;
for (int index = 0; index < word.length(); ++index) {
char content = word.charAt(index);
content = word.charAt(index);

if (current.isEnd)
break;
Expand All @@ -79,6 +92,6 @@ public boolean search(String word) {
else
return false;
}
return true;
return current.isEnd;
}
}

0 comments on commit b90f34d

Please sign in to comment.