@Override final protected int getIdFromValueImpl(T value, int roundingFlag) { if (enableCache && roundingFlag == 0) { HashMap cache = valueToIdCache.get(); // SoftReference to skip cache // gracefully when short of // memory if (cache != null) { Integer id = null; id = (Integer) cache.get(value); if (id != null) return id.intValue(); byte[] valueBytes = bytesConvert.convertToBytes(value); id = getIdFromValueBytes(valueBytes, 0, valueBytes.length, roundingFlag); cache.put(value, id); return id; } } byte[] valueBytes = bytesConvert.convertToBytes(value); return getIdFromValueBytes(valueBytes, 0, valueBytes.length, roundingFlag); }
for (int i = 0; i < times; i++) { for (int j = 0; j < n; j++) { keep |= dict.getIdFromValueBytes(array[j], 0, array[j].length);
int nullId2 = dict.getIdFromValueBytes(null, 0, 0); assertEquals(dict.getValueBytesFromId(nullId2, null, 0), -1); assertEquals(nullId, nullId2);
@Override final protected int getIdFromValueImpl(T value, int roundingFlag) { if (enableCache && roundingFlag == 0) { HashMap cache = valueToIdCache.get(); // SoftReference to skip cache gracefully when short of memory if (cache != null) { Integer id = null; id = (Integer) cache.get(value); if (id != null) return id.intValue(); byte[] valueBytes = bytesConvert.convertToBytes(value); id = getIdFromValueBytes(valueBytes, 0, valueBytes.length, roundingFlag); cache.put(value, id); return id; } } byte[] valueBytes = bytesConvert.convertToBytes(value); return getIdFromValueBytes(valueBytes, 0, valueBytes.length, roundingFlag); }
public static void main(String[] args) throws Exception { TrieDictionaryBuilder<String> b = new TrieDictionaryBuilder<String>(new StringBytesConverter()); b.addValue(""); b.print(); b.addValue("part"); b.print(); b.addValue("part"); b.print(); b.addValue("par"); b.print(); b.addValue("partition"); b.print(); b.addValue("party"); b.print(); b.addValue("parties"); b.print(); b.addValue("paint"); b.print(); TrieDictionary<String> dict = b.build(0); dict.dump(System.out); dict.getIdFromValueBytes(new byte[10], 0, 0); } }