/** * Flatten the trie into a byte array for a minimized memory footprint. * Lookup remains fast. Cost is inflexibility to modify (becomes immutable). * <p> * Flattened node structure is HEAD + NODEs, for each node: * - o byte, offset to child node, o = stats.mbpn_sizeChildOffset * - 1 bit, isLastChild flag, the 1st MSB of o * - 1 bit, isEndOfValue flag, the 2nd MSB of o * - c byte, number of values beneath, c = stats.mbpn_sizeNoValueBeneath * - 1 byte, number of value bytes * - n byte, value bytes */ public TrieDictionary<T> build(int baseId) { byte[] trieBytes = buildTrieBytes(baseId); TrieDictionary<T> r = new TrieDictionary<T>(trieBytes); return r; }
ArrayList<TrieDictionary<T>> trees = new ArrayList<>(); for (int i = 0; i < treeSize; i++) { TrieDictionary<T> dict = new TrieDictionary<>(); dict.readFields(in); trees.add(dict);
this.dict = new TrieDictionary<String>(); dict.readFields(in); dict = new TrieDictionary<String>();
private static TrieDictionary<String> testSerialize(TrieDictionary<String> dict) { try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dataout = new DataOutputStream(bout); dict.write(dataout); dataout.close(); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); DataInputStream datain = new DataInputStream(bin); TrieDictionary<String> r = new TrieDictionary<String>(); r.readFields(datain); datain.close(); return r; } catch (IOException e) { throw new RuntimeException(e); } }
/** * Flatten the trie into a byte array for a minimized memory footprint. * Lookup remains fast. Cost is inflexibility to modify (becomes immutable). * * Flattened node structure is HEAD + NODEs, for each node: - o byte, offset * to child node, o = stats.mbpn_sizeChildOffset - 1 bit, isLastChild flag, * the 1st MSB of o - 1 bit, isEndOfValue flag, the 2nd MSB of o - c byte, * number of values beneath, c = stats.mbpn_sizeNoValueBeneath - 1 byte, * number of value bytes - n byte, value bytes */ public TrieDictionary<T> build(int baseId) { byte[] trieBytes = buildTrieBytes(baseId); TrieDictionary<T> r = new TrieDictionary<T>(trieBytes); return r; }
private static TrieDictionary<String> testSerialize(TrieDictionary<String> dict) { try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dataout = new DataOutputStream(bout); dict.write(dataout); dataout.close(); ByteArrayInputStream bin = new ByteArrayInputStream(bout.toByteArray()); DataInputStream datain = new DataInputStream(bin); TrieDictionary<String> r = new TrieDictionary<String>(); r.readFields(datain); datain.close(); return r; } catch (IOException e) { throw new RuntimeException(e); } }
/** * Flatten the trie into a byte array for a minimized memory footprint. * Lookup remains fast. Cost is inflexibility to modify (becomes immutable). * * Flattened node structure is HEAD + NODEs, for each node: - o byte, offset * to child node, o = stats.mbpn_sizeChildOffset - 1 bit, isLastChild flag, * the 1st MSB of o - 1 bit, isEndOfValue flag, the 2nd MSB of o - c byte, * number of values beneath, c = stats.mbpn_sizeNoValueBeneath - 1 byte, * number of value bytes - n byte, value bytes */ public TrieDictionary<T> build(int baseId) { byte[] trieBytes = buildTrieBytes(baseId); TrieDictionary<T> r = new TrieDictionary<T>(trieBytes); return r; }
/** * Flatten the trie into a byte array for a minimized memory footprint. * Lookup remains fast. Cost is inflexibility to modify (becomes immutable). * <p> * Flattened node structure is HEAD + NODEs, for each node: * - o byte, offset to child node, o = stats.mbpn_sizeChildOffset * - 1 bit, isLastChild flag, the 1st MSB of o * - 1 bit, isEndOfValue flag, the 2nd MSB of o * - c byte, number of values beneath, c = stats.mbpn_sizeNoValueBeneath * - 1 byte, number of value bytes * - n byte, value bytes */ public TrieDictionary<T> build(int baseId) { byte[] trieBytes = buildTrieBytes(baseId); TrieDictionary<T> r = new TrieDictionary<T>(trieBytes); return r; }
ArrayList<TrieDictionary<T>> trees = new ArrayList<>(); for (int i = 0; i < treeSize; i++) { TrieDictionary<T> dict = new TrieDictionary<>(); dict.readFields(in); trees.add(dict);
this.dict = new TrieDictionary<String>(); dict.readFields(in); dict = new TrieDictionary<String>();
this.dict = new TrieDictionary<String>(); dict.readFields(in);