Skip to content

Commit abf5064

Browse files
committed
clusterlin: simplify DepGraphFormatter::Ser
This does not change the serialization format. It turns out that it is unnecessary to keep track of the order of transactions in the so-far reconstructed DepGraph to decide how far from the end to insert a new transaction.
1 parent eaab55f commit abf5064

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

src/test/util/cluster_linearize.h

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,8 @@ struct DepGraphFormatter
134134
});
135135

136136
/** Which transactions the deserializer already knows when it has deserialized what has
137-
* been serialized here so far, and in what order. */
138-
std::vector<ClusterIndex> rebuilt_order;
139-
rebuilt_order.reserve(depgraph.TxCount());
137+
* been serialized here so far. */
138+
SetType done;
140139

141140
// Loop over the transactions in topological order.
142141
for (ClusterIndex topo_idx = 0; topo_idx < topo_order.size(); ++topo_idx) {
@@ -166,14 +165,11 @@ struct DepGraphFormatter
166165
}
167166
}
168167
// Write position information.
169-
ClusterIndex insert_distance = 0;
170-
while (insert_distance < rebuilt_order.size()) {
171-
// Loop to find how far from the end in rebuilt_order to insert.
172-
if (idx > *(rebuilt_order.end() - 1 - insert_distance)) break;
173-
++insert_distance;
174-
}
175-
rebuilt_order.insert(rebuilt_order.end() - insert_distance, idx);
176-
s << VARINT(diff + insert_distance);
168+
// The new transaction is to be inserted N positions back from the end of the cluster.
169+
// Emit N to indicate that that many insertion choices are skipped.
170+
auto skips = (done - SetType::Fill(idx)).Count();
171+
s << VARINT(diff + skips);
172+
done.Set(idx);
177173
}
178174

179175
// Output a final 0 to denote the end of the graph.

0 commit comments

Comments
 (0)