clusterlin: abstract out functions from MergeStep (refactor)

This is a simple refactor to make the code more readable.
This commit is contained in:
Pieter Wuille
2025-12-26 10:42:19 -05:00
committed by Pieter Wuille
parent b75574a653
commit cbd684a471

View File

@@ -864,12 +864,24 @@ private:
return INVALID_SET_IDX;
}
/** Perform an upward or downward merge step, on the specified chunk. Returns the merged chunk,
* or INVALID_SET_IDX if no merge took place. */
/** Activate a dependency from chunk_idx to merge_chunk_idx (if !DownWard), or a dependency
* from merge_chunk_idx to chunk_idx (if DownWard). Return the index of the merged chunk. */
template<bool DownWard>
SetIdx MergeStep(SetIdx chunk_idx) noexcept
SetIdx MergeChunksDirected(SetIdx chunk_idx, SetIdx merge_chunk_idx) noexcept
{
if constexpr (DownWard) {
return MergeChunks(chunk_idx, merge_chunk_idx);
} else {
return MergeChunks(merge_chunk_idx, chunk_idx);
}
}
/** Determine which chunk to merge chunk_idx with, or INVALID_SET_IDX if none. */
template<bool DownWard>
SetIdx PickMergeCandidate(SetIdx chunk_idx) noexcept
{
/** Information about the chunk. */
Assume(m_chunk_idxs[chunk_idx]);
auto& chunk_info = m_set_info[chunk_idx];
SetType chunk_txn = chunk_info.transactions;
// Iterate over all transactions in the chunk, figuring out which other chunk each
@@ -913,18 +925,21 @@ private:
}
}
}
// Stop if there are no candidate chunks to merge with.
if (best_other_chunk_idx == INVALID_SET_IDX) return INVALID_SET_IDX;
if constexpr (DownWard) {
chunk_idx = MergeChunks(chunk_idx, best_other_chunk_idx);
} else {
chunk_idx = MergeChunks(best_other_chunk_idx, chunk_idx);
}
return best_other_chunk_idx;
}
/** Perform an upward or downward merge step, on the specified chunk. Returns the merged chunk,
* or INVALID_SET_IDX if no merge took place. */
template<bool DownWard>
SetIdx MergeStep(SetIdx chunk_idx) noexcept
{
auto merge_chunk_idx = PickMergeCandidate<DownWard>(chunk_idx);
if (merge_chunk_idx == INVALID_SET_IDX) return INVALID_SET_IDX;
chunk_idx = MergeChunksDirected<DownWard>(chunk_idx, merge_chunk_idx);
Assume(chunk_idx != INVALID_SET_IDX);
return chunk_idx;
}
/** Perform an upward or downward merge sequence on the specified transaction. */
template<bool DownWard>
void MergeSequence(TxIdx tx_idx) noexcept