txgraph: Abstract out ClearLocator (refactor)

Move a number of related modifications to TxGraphImpl into a separate
function for removal of transactions. This is preparation for a later
commit where this will be useful in more than one place.
This commit is contained in:
Pieter Wuille 2024-11-24 10:00:59 -05:00
parent 34aa3da5ad
commit c99c7300b4

View file

@ -274,6 +274,8 @@ public:
ClusterSetIndex InsertCluster(std::unique_ptr<Cluster>&& cluster, QualityLevel quality) noexcept;
/** Change the QualityLevel of a Cluster (identified by old_quality and old_index). */
void SetClusterQuality(QualityLevel old_quality, ClusterSetIndex old_index, QualityLevel new_quality) noexcept;
/** Make a transaction not exist. It must currently exist. */
void ClearLocator(GraphIndex index) noexcept;
// Functions for handling Refs.
@ -335,6 +337,16 @@ public:
void SanityCheck() const final;
};
void TxGraphImpl::ClearLocator(GraphIndex idx) noexcept
{
auto& entry = m_entries[idx];
Assume(entry.m_locator.IsPresent());
// Change the locator from Present to Missing.
entry.m_locator.SetMissing();
// Update the transaction count.
--m_clusterset.m_txcount;
}
void Cluster::Updated(TxGraphImpl& graph) noexcept
{
// Update all the Locators for this Cluster's Entrys.
@ -385,9 +397,8 @@ void Cluster::ApplyRemovals(TxGraphImpl& graph, std::span<GraphIndex>& to_remove
// that causes it to be accessed regardless.
m_mapping[locator.index] = GraphIndex(-1);
// - Mark it as removed in the Entry's locator.
locator.SetMissing();
graph.ClearLocator(idx);
to_remove = to_remove.subspan(1);
--graph.m_clusterset.m_txcount;
} while(!to_remove.empty());
auto quality = m_quality;