Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
public static void main(String[] args)
throws IOException
{
DoubleArrayTrie da = new DoubleArrayTrie();
List<String> lines = new ArrayList<>();
try (BufferedReader reader = new BufferedReader(new FileReader("/Users/komamitsu/tmp/sorted_uuids"))) {
String line;
while ((line = reader.readLine()) != null) {
lines.add(line);
}
}
long start = System.currentTimeMillis();
da.build(lines);
long end = System.currentTimeMillis();
System.out.println("Build: " + (end - start) + " ms");
start = System.currentTimeMillis();
try (BufferedReader reader = new BufferedReader(new FileReader("/Users/komamitsu/tmp/uuids"))) {
String line;
while ((line = reader.readLine()) != null) {
int result = da.exactMatchSearch(line);
if (result < 0) {
throw new RuntimeException("Not found");
}
else {
// System.out.println("Found");
}
}
}
end = System.currentTimeMillis();
System.out.println("Scan: " + (end - start) + " ms");
}
/*
Using https://github.com/komiya-atsushi/darts-java
Build: 6092 ms
Scan: 753 ms
*/
public class Test
{
public static void main(String[] args)
throws IOException
{
PatriciaTrie patriciaTrie = new PatriciaTrie();
long start = System.currentTimeMillis();
try (BufferedReader reader = new BufferedReader(new FileReader("/Users/komamitsu/tmp/sorted_uuids"))) {
String line;
while ((line = reader.readLine()) != null) {
patriciaTrie.insert(line);
}
}
long end = System.currentTimeMillis();
System.out.println("Build0: " + (end - start) + " ms");
start = System.currentTimeMillis();
DoubleArray da = new DoubleArray(patriciaTrie);
end = System.currentTimeMillis();
System.out.println("Build1: " + (end - start) + " ms");
start = System.currentTimeMillis();
try (BufferedReader reader = new BufferedReader(new FileReader("/Users/komamitsu/tmp/uuids"))) {
String line;
while ((line = reader.readLine()) != null) {
boolean result = da.contains(line);
if (! result) {
throw new RuntimeException("Not found");
}
else {
// System.out.println("Found");
}
}
}
end = System.currentTimeMillis();
System.out.println("Scan: " + (end - start) + " ms");
}
}
/*
https://github.com/takawitter/trie4j
Build0: 1059 ms
Build1: 2461 ms
Scan: 1092 ms
*/
public class TrieHardTest
{
public static void main(String[] args)
throws IOException
{
long start = System.currentTimeMillis();
Trie<String, Object> trie = Tries.forStrings();
try (BufferedReader reader = new BufferedReader(new FileReader("/Users/komamitsu/tmp/sorted_uuids"))) {
String line;
while ((line = reader.readLine()) != null) {
trie.put(line, true);
}
}
long end = System.currentTimeMillis();
System.out.println("Build: " + (end - start) + " ms");
start = System.currentTimeMillis();
try (BufferedReader reader = new BufferedReader(new FileReader("/Users/komamitsu/tmp/uuids"))) {
String line;
while ((line = reader.readLine()) != null) {
boolean result = trie.containsKey(line);
if (!result) {
throw new RuntimeException("Not found");
}
else {
// System.out.println("Found");
}
}
}
end = System.currentTimeMillis();
System.out.println("Scan: " + (end - start) + " ms");
}
}
/*
https://github.com/ClickerMonkey/TrieHard
Build: 1931 ms
Scan: 931 ms
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment