private void initSizeOfValue() { int maxValue = 0; for (TrieDictionary<T> tree : trees) maxValue = Math.max(maxValue, tree.getSizeOfValue()); this.sizeOfValue = maxValue; }
int times = Math.max(10 * 1000 * 1000 / n, 1); // run 10 million lookups int keep = 0; // make sure JIT don't OPT OUT function calls under test byte[] valueBytes = new byte[dict.getSizeOfValue()]; long start;
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 final protected T getValueFromIdImpl(int id) { if (enableCache) { Object[] cache = idToValueCache.get(); // SoftReference to skip // cache gracefully when // short of memory if (cache != null) { int seq = calcSeqNoFromId(id); if (seq < 0 || seq >= nValues) throw new IllegalArgumentException("Not a valid ID: " + id); if (cache[seq] != null) return (T) cache[seq]; byte[] value = new byte[getSizeOfValue()]; int length = getValueBytesFromId(id, value, 0); T result = bytesConvert.convertFromBytes(value, 0, length); cache[seq] = result; return result; } } byte[] value = new byte[getSizeOfValue()]; int length = getValueBytesFromId(id, value, 0); return bytesConvert.convertFromBytes(value, 0, length); }
int times = 10 * 1000 * 1000 / n; // run 10 million lookups int keep = 0; // make sure JIT don't OPT OUT function calls under test byte[] valueBytes = new byte[dict.getSizeOfValue()]; long start;
private void initSizeOfValue() { int maxValue = 0; for (TrieDictionary<T> tree : trees) maxValue = Math.max(maxValue, tree.getSizeOfValue()); this.sizeOfValue = maxValue; }
@Override final protected T getValueFromIdImpl(int id) { if (enableCache) { Object[] cache = idToValueCache.get(); // SoftReference to skip cache gracefully when short of memory if (cache != null) { int seq = calcSeqNoFromId(id); if (seq < 0 || seq >= nValues) throw new IllegalArgumentException("Not a valid ID: " + id); if (cache[seq] != null) return (T) cache[seq]; byte[] value = new byte[getSizeOfValue()]; int length = getValueBytesFromId(id, value, 0); T result = bytesConvert.convertFromBytes(value, 0, length); cache[seq] = result; return result; } } byte[] value = new byte[getSizeOfValue()]; int length = getValueBytesFromId(id, value, 0); return bytesConvert.convertFromBytes(value, 0, length); }