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 authored and Pieter Wuille committed 2026-02-17 09:04:36 -05:00
1 parent b75574a653
commit cbd684a471
1 file changed
+26 -11
+26 -11
View File
@@ -864,12 +864,24 @@ private:
return INVALID_SET_IDX; return INVALID_SET_IDX;
} }
/** Perform an upward or downward merge step, on the specified chunk. Returns the merged chunk, /** Activate a dependency from chunk_idx to merge_chunk_idx (if !DownWard), or a dependency
* or INVALID_SET_IDX if no merge took place. */ * from merge_chunk_idx to chunk_idx (if DownWard). Return the index of the merged chunk. */
template<bool DownWard> 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. */ /** Information about the chunk. */
Assume(m_chunk_idxs[chunk_idx]);
auto& chunk_info = m_set_info[chunk_idx]; auto& chunk_info = m_set_info[chunk_idx];
SetType chunk_txn = chunk_info.transactions; SetType chunk_txn = chunk_info.transactions;
// Iterate over all transactions in the chunk, figuring out which other chunk each // 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. return best_other_chunk_idx;
if (best_other_chunk_idx == INVALID_SET_IDX) return INVALID_SET_IDX; }
if constexpr (DownWard) {
chunk_idx = MergeChunks(chunk_idx, best_other_chunk_idx); /** Perform an upward or downward merge step, on the specified chunk. Returns the merged chunk,
} else { * or INVALID_SET_IDX if no merge took place. */
chunk_idx = MergeChunks(best_other_chunk_idx, chunk_idx); 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); Assume(chunk_idx != INVALID_SET_IDX);
return chunk_idx; return chunk_idx;
} }
/** Perform an upward or downward merge sequence on the specified transaction. */ /** Perform an upward or downward merge sequence on the specified transaction. */
template<bool DownWard> template<bool DownWard>
void MergeSequence(TxIdx tx_idx) noexcept void MergeSequence(TxIdx tx_idx) noexcept