@Test public void testCache() throws Exception { List<String> words = new ArrayList<>(); TrieDictionaryBuilder<String> b = new TrieDictionaryBuilder<String>(new StringBytesConverter()); int size = 50; for (int i = 0; i < size; i++) { String word = gen(); words.add(word); b.addValue(word); } TrieDictionary<String> dict = b.build(0); String[] wordsInDict = new String[size]; for (int i = 0; i < size; i++) { String word = dict.getValueFromId(i); wordsInDict[i] = word; Assert.assertTrue(words.contains(word)); } Assert.assertEquals(size, getField(dict, "cacheMissCount")); Assert.assertEquals(0, getField(dict, "cacheHitCount")); dict.printlnStatistics(); for (int i = 0; i < size; i++) { Assert.assertTrue(dict.containsValue(wordsInDict[i])); Assert.assertTrue(dict.containsValue(wordsInDict[i])); } Assert.assertEquals(getField(dict, "cacheHitCount"), size); Assert.assertEquals(getField(dict, "cacheMissCount"), size); dict.printlnStatistics(); for (int i = 0; i < size; i++) { String word = dict.getValueFromId(i); Assert.assertEquals(wordsInDict[i], word); } Assert.assertEquals(getField(dict, "cacheHitCount"), size); dict.printlnStatistics(); for (int i = 0; i < size; i++) { byte[] word = dict.getValueByteFromId(i); Assert.assertArrayEquals(wordsInDict[i].getBytes(StandardCharsets.UTF_8), word); } Assert.assertEquals(getField(dict, "cacheHitCount"), size); dict.printlnStatistics(); dict.disableCache(); for (int i = 0; i < size; i++) { byte[] word = dict.getValueByteFromId(i); Assert.assertArrayEquals(wordsInDict[i].getBytes(StandardCharsets.UTF_8), word); } Assert.assertEquals(0, getField(dict, "cacheHitCount")); dict.printlnStatistics(); }
@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; }
TrieDictionary extends CacheDictionary<T> { @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; } }
TrieDictionary extends CacheDictionary<T> { @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; } TrieDictionary();  TrieDictionary(byte[] trieBytes); }
TrieDictionary extends CacheDictionary<T> { @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; } TrieDictionary();  TrieDictionary(byte[] trieBytes); @Override int getMinId(); @Override int getMaxId(); @Override int getSizeOfId(); @Override int getSizeOfValue(); int getStorageSizeInBytes(); @Override void write(DataOutput out); @Override void readFields(DataInput in); @Override List<T> enumeratorValues(); @Override void dump(PrintStream out); @Override int hashCode(); @Override boolean equals(Object o); @Override boolean contains(Dictionary other); static void main(String[] args); }
TrieDictionary extends CacheDictionary<T> { @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; } TrieDictionary();  TrieDictionary(byte[] trieBytes); @Override int getMinId(); @Override int getMaxId(); @Override int getSizeOfId(); @Override int getSizeOfValue(); int getStorageSizeInBytes(); @Override void write(DataOutput out); @Override void readFields(DataInput in); @Override List<T> enumeratorValues(); @Override void dump(PrintStream out); @Override int hashCode(); @Override boolean equals(Object o); @Override boolean contains(Dictionary other); static void main(String[] args); static final byte[] MAGIC; static final int MAGIC_SIZE_I; static final int BIT_IS_LAST_CHILD; static final int BIT_IS_END_OF_VALUE; }