Skip to content

Instantly share code, notes, and snippets.

@takawitter
Created June 27, 2012 12:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save takawitter/3003779 to your computer and use it in GitHub Desktop.
Save takawitter/3003779 to your computer and use it in GitHub Desktop.
Trie4J sample code
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