const uint64_t sa = m.m_src_begin + (pos - m.m_dst_begin);
used_src[m.m_src_key].emplace_back(
sa, sa + (best_end - pos));
- result.m_selected_matches.push_back(best_idx);
+ result.m_selected_edges.push_back(PlanSearchEdge{
+ best_idx, pos, best_end });
matched_blocks += block_count(pos, best_end);
++dedupe_ops;
pos = best_end;
for (auto it = edges.rbegin(); it != edges.rend(); ++it) {
const auto &e = **it;
if (e.m_dedupe) {
- result.m_selected_matches.push_back(e.m_match_idx);
+ // Recover the edge's dst span from its recorded src slice:
+ // the slice was computed as src_begin + (a - dst_begin), so
+ // the inverse gives back [a, b) exactly.
+ const auto &m = in.m_matches[e.m_match_idx];
+ const uint64_t db = m.m_dst_begin
+ + (e.m_src_begin - m.m_src_begin);
+ result.m_selected_edges.push_back(PlanSearchEdge{
+ e.m_match_idx, db,
+ db + (e.m_src_end - e.m_src_begin) });
} else {
result.m_copy_slices.push_back(
PlanSearchRegion{ e.m_copy_begin, e.m_copy_end });
uint64_t m_clone_alignment = 4096; ///< s_clone_alignment (physical credit)
};
-/// One covering returned by the search. m_selected_matches indexes into
-/// PlanSearchInputs::m_matches (the search's chosen dedupe edges, each a
-/// full match span); m_copy_slices are the leftover data gaps copied via
-/// the tempfile. m_debt is the covering's signed space-debt, equal by
-/// construction to scan_next_dst_debt() of the ChosenPlan built from it.
+/// One selected dedupe edge of a covering: which candidate match, and the
+/// dst sub-span of it the covering actually uses. The search may use
+/// disjoint sub-spans of dst-overlapping matches, so the edge's span — not
+/// the match's full span — is the authoritative statement of which dst
+/// bytes this edge serves. The src slice follows from the span:
+/// src_begin + (m_dst_begin - match.m_dst_begin), same length.
+struct PlanSearchEdge {
+ size_t m_match_idx = 0; ///< index into PlanSearchInputs::m_matches
+ uint64_t m_dst_begin = 0;
+ uint64_t m_dst_end = 0;
+};
+
+/// One covering returned by the search. m_selected_edges are the chosen
+/// dedupe edges (match index + used dst sub-span); m_copy_slices are the
+/// leftover data gaps copied via the tempfile. m_debt is the covering's
+/// signed space-debt, equal by construction to scan_next_dst_debt() of
+/// the ChosenPlan built from it.
struct PlanSearchResult {
- std::vector<size_t> m_selected_matches; ///< indices into m_matches
+ std::vector<PlanSearchEdge> m_selected_edges; ///< chosen dedupe edges
std::vector<PlanSearchRegion> m_copy_slices; ///< unclaimed copy gaps
size_t m_matched_blocks = 0;
double m_debt = 0.0;
const BeesRewritePolicy &policy, const PlanSearchResult &r)
{
return scan_next_covering_debt(in, policy,
- r.m_selected_matches.size(), r.m_copy_slices.size(),
+ r.m_selected_edges.size(), r.m_copy_slices.size(),
r.m_matched_blocks);
}
const auto res = scan_next_plan_shortest_path(in, policy);
assert(res.has_value());
- assert(res->m_selected_matches.empty()); // no dedupe pays at 50 refs
+ assert(res->m_selected_edges.empty()); // no dedupe pays at 50 refs
assert(res->m_matched_blocks == 0);
assert(res->m_debt == result_recomputed_debt(in, policy, *res));
const auto omin = oracle_min_debt(in, policy);
// Committing the interior match makes 3 ops (copy [0,5), dedupe [5,6),
// copy [6,10)); leaving it is 1 copy op. refs_added jumps by 50*2,
// dwarfing the 4096-byte credit, so the search leaves it as copy.
- assert(res->m_selected_matches.empty());
+ assert(res->m_selected_edges.empty());
assert(res->m_copy_slices.size() == 1);
assert(res->m_debt == result_recomputed_debt(in, policy, *res));
assert(res->m_debt == *oracle_min_debt(in, policy));
const auto in1 = make_inputs(10, { {5, 6} }, /*ref=*/1);
const auto res1 = scan_next_plan_shortest_path(in1, policy);
assert(res1.has_value());
- assert(res1->m_selected_matches.size() == 1);
+ assert(res1->m_selected_edges.size() == 1);
assert(res1->m_debt == *oracle_min_debt(in1, policy));
}
const auto res = scan_next_plan_shortest_path(in, policy);
assert(res.has_value());
- assert(res->m_selected_matches.size() == 2); // both selected
+ assert(res->m_selected_edges.size() == 2); // both selected
assert(res->m_copy_slices.empty()); // nothing left to copy
assert(res->m_matched_blocks == 8);
assert(res->m_debt == result_recomputed_debt(in, policy, *res));
// dedupe[0,4) is not a single match... so dedupe one 2-block match +
// one copy = 2 ops), so the search returns something.
assert(res.has_value());
- const size_t total_ops = res->m_selected_matches.size()
+ const size_t total_ops = res->m_selected_edges.size()
+ res->m_copy_slices.size() + in.m_hole_ops;
assert(total_ops <= policy.m_total_max);
// And it matches the oracle minimum among limit-satisfying coverings.
// collapses the split); they are the acceptance gate's authority,
// so the search may return a covering that exceeds a per-type cap
// when total-max is set above it.
- const size_t total_ops = res->m_selected_matches.size()
+ const size_t total_ops = res->m_selected_edges.size()
+ res->m_copy_slices.size() + in.m_hole_ops;
assert(total_ops <= policy.m_total_max);
}
const auto res = scan_next_plan_shortest_path(in_full, policy);
assert(res.has_value());
assert(res->m_copy_slices.empty());
- assert(res->m_selected_matches.size() == 1);
+ assert(res->m_selected_edges.size() == 1);
assert(res->m_debt == result_recomputed_debt(in_full, policy, *res));
// force-rewrite lifts the compressed copy prohibition: a compressed dst
in_force.m_force_rewrite = true;
const auto rf = scan_next_plan_shortest_path(in_force, policy);
assert(rf.has_value());
- assert(rf->m_selected_matches.empty());
+ assert(rf->m_selected_edges.empty());
assert(rf->m_copy_slices.size() == 1); // one copy op, no fragment
assert(rf->m_debt == result_recomputed_debt(in_force, policy, *rf));
// cover is within the op limits.
assert(greedy->m_matched_blocks == 20);
assert(greedy->m_copy_slices.empty());
- assert(greedy->m_selected_matches.size() == 3);
- assert(greedy->m_selected_matches.size() <= policy.m_dedupe_max);
+ assert(greedy->m_selected_edges.size() == 3);
+ assert(greedy->m_selected_edges.size() <= policy.m_dedupe_max);
// Debt reconciles by construction, and equals both the exact DP and the
// oracle minimum — greedy is optimal on a coverable extent.
policy.m_plan_max_vertices = 16384;
const auto dp = scan_next_plan_shortest_path(in, policy);
assert(dp.has_value());
- assert(dp->m_selected_matches.size() == 1);
- assert(dp->m_selected_matches[0] == hi); // canonical src chosen
+ assert(dp->m_selected_edges.size() == 1);
+ assert(dp->m_selected_edges[0].m_match_idx == hi); // canonical src chosen
assert(dp->m_debt == result_recomputed_debt(in, policy, *dp));
// Greedy fallback (tiny V budget forces it): same decision, and the
policy.m_plan_max_vertices = 1;
const auto gr = scan_next_plan_shortest_path(in, policy);
assert(gr.has_value());
- assert(gr->m_selected_matches.size() == 1);
- assert(gr->m_selected_matches[0] == hi);
+ assert(gr->m_selected_edges.size() == 1);
+ assert(gr->m_selected_edges[0].m_match_idx == hi);
assert(gr->m_debt == result_recomputed_debt(in, policy, *gr));
}
policy.m_plan_max_vertices = 16384;
const auto dp = scan_next_plan_shortest_path(in, policy);
assert(dp.has_value());
- assert(dp->m_selected_matches.size() == 1);
- assert(dp->m_selected_matches[0] == 0); // full-span src wins on reach
+ assert(dp->m_selected_edges.size() == 1);
+ assert(dp->m_selected_edges[0].m_match_idx == 0); // full-span src wins on reach
}
}