public static void serialize(DAG dag, DataOutput out) throws IOException { final ObjectId treeId = dag.originalTreeId; final STATE state = dag.getState(); final long childCount = dag.getTotalChildCount(); final Collection<NodeId> children = dag.children.values(); final Set<TreeId> buckets = dag.buckets; treeId.writeTo(out); out.writeByte(state.ordinal()); Varint.writeUnsignedVarLong(childCount, out); Varint.writeUnsignedVarInt(children.size(), out); Varint.writeUnsignedVarInt(buckets.size(), out); for (NodeId nodeid : children) { NodeId.write(nodeid, out); } for (TreeId tid : buckets) { byte[] bucketIndicesByDepth = tid.bucketIndicesByDepth; Varint.writeUnsignedVarInt(bucketIndicesByDepth.length, out); out.write(bucketIndicesByDepth); } }
public static DAG deserialize(TreeId id, DataInput in) throws IOException { final ObjectId treeId = ObjectId.readFrom(in); final STATE state = STATE.values()[in.readByte() & 0xFF]; final long childCount = Varint.readUnsignedVarLong(in); final int childrenSize = Varint.readUnsignedVarInt(in); final int bucketSize = Varint.readUnsignedVarInt(in); Set<NodeId> children = ImmutableSet.of(); Set<TreeId> buckets = ImmutableSet.of(); if (childrenSize > 0) { children = new HashSet<>(); for (int i = 0; i < childrenSize; i++) { NodeId nid = NodeId.read(in); children.add(nid); } } if (bucketSize > 0) { buckets = new HashSet<>(); for (int i = 0; i < bucketSize; i++) { final int len = Varint.readUnsignedVarInt(in); final byte[] bucketIndicesByDepth = new byte[len]; in.readFully(bucketIndicesByDepth); buckets.add(new TreeId(bucketIndicesByDepth)); } } DAG dag = new DAG(id, treeId, childCount, state, children, buckets); return dag; }
final DAG root = this.root; final STATE rootState = root.getState(); if (rootState.equals(STATE.CHANGED)) { if (0 == root.numBuckets()) { result = buildLeafTree(root);
final DAG currentRoot = this.root; final STATE rootState = currentRoot.getState(); if (rootState.equals(STATE.CHANGED)) { if (0 == currentRoot.numBuckets()) { builtTree = buildLeafTree(currentRoot);
public static DAG deserialize(TreeId id, DataInput in) throws IOException { final ObjectId treeId = ObjectId.readFrom(in); final STATE state = STATE.values()[in.readByte() & 0xFF]; final long childCount = in.readLong(); final int childrenSize = in.readInt(); final int bucketSize = in.readShort(); Map<String, NodeId> children = ImmutableMap.of(); Set<TreeId> buckets = ImmutableSet.of(); if (childrenSize > 0) { children = new HashMap<>(); for (int i = 0; i < childrenSize; i++) { NodeId nid = DAGSerializer.read(in); children.put(nid.name(), nid); } } if (bucketSize > 0) { buckets = new HashSet<>(); for (int i = 0; i < bucketSize; i++) { final int len = in.readShort(); final byte[] bucketIndicesByDepth = new byte[len]; in.readFully(bucketIndicesByDepth); buckets.add(new TreeId(bucketIndicesByDepth)); } } return new DAG(id, treeId, childCount, state, children, buckets); }
public static void serialize(DAG dag, DataOutput out) throws IOException { final ObjectId treeId = dag.originalTreeId(); final STATE state = dag.getState(); final long childCount = dag.getTotalChildCount(); treeId.writeTo(out); out.writeByte(state.ordinal()); out.writeLong(childCount); out.writeInt(dag.numChildren()); out.writeShort(dag.numBuckets()); dag.forEachChild(nodeid -> DAGSerializer.write(nodeid, out)); dag.forEachBucket(tid -> { byte[] bucketIndicesByDepth = tid.bucketIndicesByDepth; try { out.writeShort(bucketIndicesByDepth.length); out.write(bucketIndicesByDepth); } catch (IOException e) { throw new RuntimeException(e); } }); }