Created
June 27, 2012 12:30
-
-
Save takawitter/3003779 to your computer and use it in GitHub Desktop.
Trie4J sample code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.trie4j.doublearray.DoubleArray; | |
import org.trie4j.louds.LOUDSTrie; | |
import org.trie4j.patricia.simple.PatriciaTrie; | |
public class Sample { | |
public static void main(String[] args) throws Exception{ | |
PatriciaTrie pat = new PatriciaTrie(); | |
pat.insert("Hello"); | |
pat.insert("World"); | |
pat.insert("Wonder"); | |
pat.insert("Wonderful!"); | |
pat.contains("Hello"); // -> true | |
pat.predictiveSearch("Wo"); // -> {"Wonder", "Wonderful!", "World"} as Iterable<String> | |
DoubleArray da = new DoubleArray(pat); // construct DoubleArray from existing Trie | |
da.contains("World"); // -> true | |
LOUDSTrie lt = new LOUDSTrie(pat); // construct LOUDS succinct Trie | |
lt.contains("Wonderful!"); // -> true | |
lt.commonPrefixSearch("Wonderful!"); // -> {"Wonder", "Wonderful!"} as Iterable<String> | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment