@Test public void longDictRoundingFlagTest() { TreeSet<String> set = new TreeSet<>(new Comparator<String>() { @Override public int compare(String o1, String o2) { try { Long l1 = Long.parseLong(o1); Long l2 = Long.parseLong(o2); return l1.compareTo(l2); } catch (NumberFormatException e) { e.printStackTrace(); return 0; } } }); int num = 10000; int k = -48481; int size = 0; StringBytesConverter converter = new StringBytesConverter(); for (int i = 0; i < num; i++) { String value = k + ""; set.add(value); k += 1; String basic = "-9999999999999952517"; size += converter.convertToBytes(basic).length; } System.out.println("tree num:" + size); int treeNum = 5; TrieDictionaryForestBuilder builder = new NumberDictionaryForestBuilder(0); builder.setMaxTrieTreeSize(size / treeNum); Iterator<String> it = set.iterator(); while (it.hasNext()) builder.addValue(it.next()); TrieDictionaryForest<String> dict = builder.build(); System.out.println(dict.getTrees().size()); int testTimes = 10 * 10000; Random rand = new Random(System.currentTimeMillis()); for (int i = 0; i < testTimes; i++) { String query = rand.nextInt(2 * num) + ""; try { int id = dict.getIdFromValue(query, 1); assertEquals(set.ceiling(query), dict.getValueFromId(id)); } catch (IllegalArgumentException e) { assertNull(set.ceiling(query)); } } for (int i = 0; i < testTimes; i++) { String query = rand.nextInt(2 * num) + ""; try { int id = dict.getIdFromValue(query, -1); assertEquals(set.floor(query), dict.getValueFromId(id)); } catch (IllegalArgumentException e) { assertNull(set.floor(query)); } } }
List<TrieDictionary<T>> getTrees() { return Collections.unmodifiableList(this.trees); }
TrieDictionaryForest extends CacheDictionary<T> { List<TrieDictionary<T>> getTrees() { return Collections.unmodifiableList(this.trees); } }
TrieDictionaryForest extends CacheDictionary<T> { List<TrieDictionary<T>> getTrees() { return Collections.unmodifiableList(this.trees); } TrieDictionaryForest();  TrieDictionaryForest(ArrayList<TrieDictionary<T>> trees, ArrayList<ByteArray> valueDivide, //
                                ArrayList<Integer> accuOffset, BytesConverter<T> bytesConverter, int baseId); }
TrieDictionaryForest extends CacheDictionary<T> { List<TrieDictionary<T>> getTrees() { return Collections.unmodifiableList(this.trees); } TrieDictionaryForest();  TrieDictionaryForest(ArrayList<TrieDictionary<T>> trees, ArrayList<ByteArray> valueDivide, //
                                ArrayList<Integer> accuOffset, BytesConverter<T> bytesConverter, int baseId); @Override int getMinId(); @Override int getMaxId(); @Override int getSizeOfId(); @Override int getSizeOfValue(); @Override void dump(PrintStream out); @Override void write(DataOutput out); @Override void readFields(DataInput in); @Override boolean contains(Dictionary other); @Override int hashCode(); @Override boolean equals(Object obj); }
TrieDictionaryForest extends CacheDictionary<T> { List<TrieDictionary<T>> getTrees() { return Collections.unmodifiableList(this.trees); } TrieDictionaryForest();  TrieDictionaryForest(ArrayList<TrieDictionary<T>> trees, ArrayList<ByteArray> valueDivide, //
                                ArrayList<Integer> accuOffset, BytesConverter<T> bytesConverter, int baseId); @Override int getMinId(); @Override int getMaxId(); @Override int getSizeOfId(); @Override int getSizeOfValue(); @Override void dump(PrintStream out); @Override void write(DataOutput out); @Override void readFields(DataInput in); @Override boolean contains(Dictionary other); @Override int hashCode(); @Override boolean equals(Object obj);  }