@Override public List<T> enumeratorValues() { List<T> result = Lists.newArrayListWithExpectedSize(getSize()); byte[] buf = new byte[maxValueLength]; visitNode(headSize, buf, 0, result); return result; }
private void assertSameBehaviorAsTrie(TrieDictionaryForest<String> dict, ArrayList<String> strs, int baseId) { TrieDictionaryBuilder<String> trieBuilder = new TrieDictionaryBuilder<>(new StringBytesConverter()); for (String s : strs) { if (s != null) trieBuilder.addValue(s); } TrieDictionary<String> trie = trieBuilder.build(baseId); assertEquals(trie.getMaxId(), dict.getMaxId()); assertEquals(trie.getMinId(), dict.getMinId()); assertEquals(trie.getSize(), dict.getSize()); assertEquals(trie.getSizeOfId(), dict.getSizeOfId()); assertEquals(trie.getSizeOfValue(), dict.getSizeOfValue()); }
@Override public boolean contains(Dictionary other) { if (other.getSize() > this.getSize()) { return false; } for (int i = other.getMinId(); i <= other.getMaxId(); ++i) { T v = (T) other.getValueFromId(i); if (!this.containsValue(v)) { return false; } } return true; }
private void testEnumeratorValues(String file) throws Exception { InputStream is = new FileInputStream(file); ArrayList<String> str = loadStrings(is); TrieDictionaryBuilder<String> b = newDictBuilder(str); TrieDictionary<String> dict = b.build(0); System.out.println("Dictionary size for file " + file + " is " + dict.getSize()); Stopwatch sw = new Stopwatch(); sw.start(); List<String> values1 = dict.enumeratorValuesByParent(); System.out.println("By iterating id visit the time cost " + sw.elapsed(TimeUnit.MILLISECONDS) + " ms"); sw.reset(); sw.start(); List<String> values2 = dict.enumeratorValues(); System.out.println("By pre-order visit the time cost " + sw.elapsed(TimeUnit.MILLISECONDS) + " ms"); sw.stop(); assertEquals(Sets.newHashSet(values1), Sets.newHashSet(values2)); }
@Test public void testAllNullValue() { ArrayList<String> strs = new ArrayList<String>(); strs.add(""); TrieDictionaryBuilder<String> builder = newDictBuilder(strs); TrieDictionary<String> dict = builder.build(0); assertEquals(1, dict.getSize()); assertEquals(0, dict.getIdFromValue("")); }
@Override public List<T> enumeratorValues() { List<T> result = Lists.newArrayListWithExpectedSize(getSize()); byte[] buf = new byte[maxValueLength]; visitNode(headSize, buf, 0, result); return result; }
@Override public boolean contains(Dictionary other) { if (other.getSize() > this.getSize()) { return false; } for (int i = other.getMinId(); i <= other.getMaxId(); ++i) { T v = (T) other.getValueFromId(i); if (!this.containsValue(v)) { return false; } } return true; }