| 2155 | } |
| 2156 | |
| 2157 | std::pair<uint64_t, bool> GenericClusterImpl::Relinearize(TxGraphImpl& graph, int level, uint64_t max_cost) noexcept |
| 2158 | { |
| 2159 | // We can only relinearize Clusters that do not need splitting. |
| 2160 | Assume(!NeedsSplitting()); |
| 2161 | // No work is required for Clusters which are already optimally linearized. |
| 2162 | if (IsOptimal()) return {0, false}; |
| 2163 | // Invoke the actual linearization algorithm (passing in the existing one). |
| 2164 | uint64_t rng_seed = graph.m_rng.rand64(); |
| 2165 | const auto fallback_order = [&](DepGraphIndex a, DepGraphIndex b) noexcept { |
| 2166 | const auto ref_a = graph.m_entries[m_mapping[a]].m_ref; |
| 2167 | const auto ref_b = graph.m_entries[m_mapping[b]].m_ref; |
| 2168 | return graph.m_fallback_order(*ref_a, *ref_b); |
| 2169 | }; |
| 2170 | auto [linearization, optimal, cost] = Linearize( |
| 2171 | /*depgraph=*/m_depgraph, |
| 2172 | /*max_cost=*/max_cost, |
| 2173 | /*rng_seed=*/rng_seed, |
| 2174 | /*fallback_order=*/fallback_order, |
| 2175 | /*old_linearization=*/m_linearization, |
| 2176 | /*is_topological=*/IsTopological()); |
| 2177 | // Postlinearize to improve the linearization (if optimal, only the sub-chunk order). |
| 2178 | // This also guarantees that all chunks are connected (even when non-optimal). |
| 2179 | PostLinearize(m_depgraph, linearization); |
| 2180 | // Update the linearization. |
| 2181 | m_linearization = std::move(linearization); |
| 2182 | // Update the Cluster's quality. |
| 2183 | bool improved = false; |
| 2184 | if (optimal) { |
| 2185 | graph.SetClusterQuality(level, m_quality, m_setindex, QualityLevel::OPTIMAL); |
| 2186 | improved = true; |
| 2187 | } else if (max_cost >= graph.m_acceptable_cost && !IsAcceptable()) { |
| 2188 | graph.SetClusterQuality(level, m_quality, m_setindex, QualityLevel::ACCEPTABLE); |
| 2189 | improved = true; |
| 2190 | } else if (!IsTopological()) { |
| 2191 | graph.SetClusterQuality(level, m_quality, m_setindex, QualityLevel::NEEDS_RELINEARIZE); |
| 2192 | improved = true; |
| 2193 | } |
| 2194 | // Update the Entry objects. |
| 2195 | Updated(graph, /*level=*/level, /*rename=*/false); |
| 2196 | return {cost, improved}; |
| 2197 | } |
| 2198 | |
| 2199 | std::pair<uint64_t, bool> SingletonClusterImpl::Relinearize(TxGraphImpl& graph, int level, uint64_t max_cost) noexcept |
| 2200 | { |
no test coverage detected