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;
@Test public void testMerge() { // mimic the logic as in MergeCuboidMapper NumberDictionaryForestBuilder b1 = new NumberDictionaryForestBuilder(); b1.addValue("0"); b1.addValue("3"); b1.addValue("23"); TrieDictionaryForest<String> dict1 = b1.build(); NumberDictionaryForestBuilder b2 = new NumberDictionaryForestBuilder(); b2.addValue("0"); b2.addValue("2"); b2.addValue("3"); b2.addValue("15"); b2.addValue("23"); TrieDictionaryForest<String> dict2 = b2.build(); assertTrue(dict1.getSizeOfId() == dict2.getSizeOfId()); assertTrue(dict1.getSizeOfValue() == dict2.getSizeOfValue()); { int newId = dict2.getIdFromValue(dict1.getValueFromId(0)); assertTrue(newId == 0); } { int newId = dict2.getIdFromValue(dict1.getValueFromId(1)); assertTrue(newId == 2); } { int newId = dict2.getIdFromValue(dict1.getValueFromId(2)); assertTrue(newId == 4); } }
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()); }