@@ -139,10 +139,12 @@ class Cluster
139
139
140
140
// Functions that implement the Cluster-specific side of public TxGraph functions.
141
141
142
- /* * Get a vector of Refs for the ancestors of a given Cluster element. */
143
- std::vector<TxGraph::Ref*> GetAncestorRefs (const TxGraphImpl& graph, DepGraphIndex idx) noexcept ;
144
- /* * Get a vector of Refs for the descendants of a given Cluster element. */
145
- std::vector<TxGraph::Ref*> GetDescendantRefs (const TxGraphImpl& graph, DepGraphIndex idx) noexcept ;
142
+ /* * Process elements from the front of args that apply to this cluster, and append Refs for the
143
+ * union of their ancestors to output. */
144
+ void GetAncestorRefs (const TxGraphImpl& graph, std::span<std::pair<Cluster*, DepGraphIndex>>& args, std::vector<TxGraph::Ref*>& output) noexcept ;
145
+ /* * Process elements from the front of args that apply to this cluster, and append Refs for the
146
+ * union of their descendants to output. */
147
+ void GetDescendantRefs (const TxGraphImpl& graph, std::span<std::pair<Cluster*, DepGraphIndex>>& args, std::vector<TxGraph::Ref*>& output) noexcept ;
146
148
/* * Get a vector of Refs for all elements of this Cluster, in linearization order. */
147
149
std::vector<TxGraph::Ref*> GetClusterRefs (const TxGraphImpl& graph) noexcept ;
148
150
/* * Get the individual transaction feerate of a Cluster element. */
@@ -1469,30 +1471,42 @@ bool TxGraphImpl::Exists(const Ref& arg, bool main_only) noexcept
1469
1471
return cluster != nullptr ;
1470
1472
}
1471
1473
1472
- std::vector<TxGraph::Ref*> Cluster::GetAncestorRefs (const TxGraphImpl& graph, DepGraphIndex idx ) noexcept
1474
+ void Cluster::GetAncestorRefs (const TxGraphImpl& graph, std::span<std::pair<Cluster*, DepGraphIndex>>& args, std::vector<TxGraph::Ref*>& output ) noexcept
1473
1475
{
1474
- std::vector<TxGraph::Ref*> ret;
1475
- ret.reserve (m_depgraph.Ancestors (idx).Count ());
1476
+ /* * The union of all ancestors to be returned. */
1477
+ SetType ancestors_union;
1478
+ // Process elements from the front of args, as long as they apply.
1479
+ while (!args.empty ()) {
1480
+ if (args.front ().first != this ) break ;
1481
+ ancestors_union |= m_depgraph.Ancestors (args.front ().second );
1482
+ args = args.subspan (1 );
1483
+ }
1484
+ Assume (ancestors_union.Any ());
1476
1485
// Translate all ancestors (in arbitrary order) to Refs (if they have any), and return them.
1477
- for (auto idx : m_depgraph. Ancestors (idx) ) {
1486
+ for (auto idx : ancestors_union ) {
1478
1487
const auto & entry = graph.m_entries [m_mapping[idx]];
1479
1488
Assume (entry.m_ref != nullptr );
1480
- ret .push_back (entry.m_ref );
1489
+ output .push_back (entry.m_ref );
1481
1490
}
1482
- return ret;
1483
1491
}
1484
1492
1485
- std::vector<TxGraph::Ref*> Cluster::GetDescendantRefs (const TxGraphImpl& graph, DepGraphIndex idx ) noexcept
1493
+ void Cluster::GetDescendantRefs (const TxGraphImpl& graph, std::span<std::pair<Cluster*, DepGraphIndex>>& args, std::vector<TxGraph::Ref*>& output ) noexcept
1486
1494
{
1487
- std::vector<TxGraph::Ref*> ret;
1488
- ret.reserve (m_depgraph.Descendants (idx).Count ());
1495
+ /* * The union of all descendants to be returned. */
1496
+ SetType descendants_union;
1497
+ // Process elements from the front of args, as long as they apply.
1498
+ while (!args.empty ()) {
1499
+ if (args.front ().first != this ) break ;
1500
+ descendants_union |= m_depgraph.Descendants (args.front ().second );
1501
+ args = args.subspan (1 );
1502
+ }
1503
+ Assume (descendants_union.Any ());
1489
1504
// Translate all descendants (in arbitrary order) to Refs (if they have any), and return them.
1490
- for (auto idx : m_depgraph. Descendants (idx) ) {
1505
+ for (auto idx : descendants_union ) {
1491
1506
const auto & entry = graph.m_entries [m_mapping[idx]];
1492
1507
Assume (entry.m_ref != nullptr );
1493
- ret .push_back (entry.m_ref );
1508
+ output .push_back (entry.m_ref );
1494
1509
}
1495
- return ret;
1496
1510
}
1497
1511
1498
1512
std::vector<TxGraph::Ref*> Cluster::GetClusterRefs (const TxGraphImpl& graph) noexcept
@@ -1539,7 +1553,11 @@ std::vector<TxGraph::Ref*> TxGraphImpl::GetAncestors(const Ref& arg, bool main_o
1539
1553
auto cluster = FindCluster (GetRefIndex (arg), level);
1540
1554
if (cluster == nullptr ) return {};
1541
1555
// Dispatch to the Cluster.
1542
- return cluster->GetAncestorRefs (*this , m_entries[GetRefIndex (arg)].m_locator [cluster->m_level ].index );
1556
+ std::pair<Cluster*, DepGraphIndex> match = {cluster, m_entries[GetRefIndex (arg)].m_locator [cluster->m_level ].index };
1557
+ auto matches = std::span (&match, 1 );
1558
+ std::vector<TxGraph::Ref*> ret;
1559
+ cluster->GetAncestorRefs (*this , matches, ret);
1560
+ return ret;
1543
1561
}
1544
1562
1545
1563
std::vector<TxGraph::Ref*> TxGraphImpl::GetDescendants (const Ref& arg, bool main_only) noexcept
@@ -1556,7 +1574,11 @@ std::vector<TxGraph::Ref*> TxGraphImpl::GetDescendants(const Ref& arg, bool main
1556
1574
auto cluster = FindCluster (GetRefIndex (arg), level);
1557
1575
if (cluster == nullptr ) return {};
1558
1576
// Dispatch to the Cluster.
1559
- return cluster->GetDescendantRefs (*this , m_entries[GetRefIndex (arg)].m_locator [cluster->m_level ].index );
1577
+ std::pair<Cluster*, DepGraphIndex> match = {cluster, m_entries[GetRefIndex (arg)].m_locator [cluster->m_level ].index };
1578
+ auto matches = std::span (&match, 1 );
1579
+ std::vector<TxGraph::Ref*> ret;
1580
+ cluster->GetDescendantRefs (*this , matches, ret);
1581
+ return ret;
1560
1582
}
1561
1583
1562
1584
std::vector<TxGraph::Ref*> TxGraphImpl::GetCluster (const Ref& arg, bool main_only) noexcept
0 commit comments