はおそらく、あなたは私のTrieMap
またはTrieSet
実装(found here)をテストしたいと思いますか?私は特にこのような場合のためにそれらを書いた。今まで私はString
とbyte[]
のキーの試行を実装しました。
TrieSet<String> t = Tries.newStringTrieSet();
t.add("hello");
t.add("help");
t.add("hell");
t.add("helmet");
t.add("hemp");
List<String> resultsA = new ArrayList<>();
t.findElements("hel", true, resultsA); // search for prefix
List<String> resultsB = new ArrayList<>();
t.findElements("ell", false, resultsB); // search for substring
System.out.println("A: " + resultsA);
System.out.println("B: " + resultsB);
これは印刷になります。パフォーマンスは
//put all your words to an ArrayList and sort the list.
List <String> arr = new Arraylist<>();
while(there is next)
arr.add(theWord)
Collections.sort(arr);
//this is your search method
boolean mysearch(keyword){
return Collections.binarySearch(arr, keyword)
}
です:
A: [hell, hello, helmet, help]
B: [hell, hello]
[HashSet](http://docs.oracle.com/javase/7/docs/api/java/util/HashSet.html)のようなサウンドが適しています。 – Keppil
[Lucene](http://lucene.apache.org/)の使用に関する考え方はありますか – SenthilPrabhu
@Keppil HashSetの問題はソートされていないことです。したがって、検索はより遅くなります。 –