4
我想在Trie的內存實現中實現高速以創建後端到自動建議/拼寫檢查程序。 是否已經有一些很好的實現基於像hazlecast這樣的內存實現。 另外哪些java開源工具最適合這類用法建議用於實現Trie的內存java應用程序中的最佳開源碼
我想在Trie的內存實現中實現高速以創建後端到自動建議/拼寫檢查程序。 是否已經有一些很好的實現基於像hazlecast這樣的內存實現。 另外哪些java開源工具最適合這類用法建議用於實現Trie的內存java應用程序中的最佳開源碼
我會使用像TreeSet這樣的普通NavigableSet。它內置並支持範圍搜索。
NavigableSet<String> words = new TreeSet<String>();
// add words.
String startsWith = ...
SortedSet<String> matching = words.subSet(startsWith, startsWith + '\uFFFF');
如果你想要更多的內存效率,你可以使用一個數組。
List<String> words = new ArrayList<String>();
words.add("aa");
words.add("ab");
words.add("ac");
words.add("ba");
Collections.sort(words);
String startsWith = "a";
int first = Collections.binarySearch(words, startsWith);
int last = Collections.binarySearch(words, startsWith.concat("\uFFFF"));
if (first < 0) first = ~first;
if (last < 0) last = ~last - 1;
for (int i = first; i <= last; i++) {
System.out.println(words.get(i));
}
此工具將是最好的 - http://sna-projects.com/cleo/quickstart.php –