71template<
typename SetType>
72class SimpleCandidateFinder
88 bool AllDone() const noexcept {
return m_todo.None(); }
104 std::vector<std::pair<SetType, SetType>>
queue;
106 queue.emplace_back(SetType{}, m_todo);
117 for (
auto split :
und) {
144template<
typename SetType>
145class ExhaustiveCandidateFinder
161 bool AllDone() const noexcept {
return m_todo.None(); }
179 for (
auto i : m_todo) {
196template<
typename SetType>
221template<
typename SetType>
284template<
typename SetType>
292 }
catch(
const std::ios_base::failure&) {}
296 for (
auto i :
todo) {
327 for (
auto j :
todo) {
342 }
catch (
const std::ios_base::failure&) {}
381 auto children =
depgraph.GetReducedChildren(i);
382 if (children.Any()) {
383 depgraph_tree.AddDependencies(BS::Singleton(i), children.First());
388 auto parents =
depgraph.GetReducedParents(i);
390 depgraph_tree.AddDependencies(BS::Singleton(parents.First()), i);
410 std::array<std::optional<std::pair<FeeFrac, TestBitSet>>, TestBitSet::Size()>
sim;
418 if (!
sim[i].has_value())
continue;
419 if (offset == 0)
return i;
433 if (!
sim[i].has_value())
continue;
449 if ((mask >> i) & 1) {
461 if (!
sim[
chl].has_value())
continue;
477 if (
sim[i].has_value()) {
498 auto idx =
real.AddTransaction(feerate);
502 if (!
sim[i].has_value()) {
508 sim[idx] = {feerate, TestBitSet::Singleton(idx)};
532 if (
sim[i].has_value()) {
535 sim[i] = std::nullopt;
572 }
catch (
const std::ios_base::failure&) {}
583 for (
auto i :
depgraph.Positions()) {
591 auto ancestors =
depgraph.Ancestors(
par) - TestBitSet::Singleton(
par);
592 if (ancestors.None())
return;
594 for (
auto i : ancestors) {
617 }
catch (
const std::ios_base::failure&) {}
622 std::optional<DepGraphIndex> picked;
627 }
catch (
const std::ios_base::failure&) {}
681 }
catch (
const std::ios_base::failure&) {}
707 }
catch (
const std::ios_base::failure&) {}
722 }
catch (
const std::ios_base::failure&) {}
733 for (
size_t i = 0; i <
chunking.size(); ++i) {
739 for (
size_t i = 1; i <
chunking.size(); ++i) {
781 }
catch (
const std::ios_base::failure&) {}
799 assert(found.transactions.Any());
803 for (
auto i : found.transactions) {
818 if (
todo.Count() <= 12) {
856 }
catch (
const std::ios_base::failure&) {}
901 }
catch (
const std::ios_base::failure&) {}
902 if (
depgraph.TxCount() <= 1)
return;
961 sfl.MakeTopological();
965 sfl.MakeTopological();
970 sfl.StartOptimizing();
973 if (!
sfl.OptimizeStep())
break;
978 sfl.StartMinimizing();
981 if (!
sfl.MinimizeStep())
break;
1001 for (
int i = 0; i < 10; ++i) {
1023 }
catch (
const std::ios_base::failure&) {}
1024 if (
depgraph.TxCount() <= 1)
return;
1111 if ((
depgraph.Ancestors(
tx2) - done).Count() == 1) {
1124 pos +=
chunk.transactions.Count();
1150 done |=
chunk1.transactions;
1170 }
catch (
const std::ios_base::failure&) {}
1215 }
catch (
const std::ios_base::failure&) {}
1268 }
catch (
const std::ios_base::failure&) {}
1269 if (
depgraph.TxCount() == 0)
return;
1278 for (
auto i :
lin) {
#define Assume(val)
Assume is the identity function.
T ConsumeIntegralInRange(T min, T max)
constexpr uint64_t rand64() noexcept
uint64_t randbits(int bits) noexcept
Generate a random (bits)-bit integer.
Minimal stream for reading from an existing byte array by std::span.
Data structure that holds a transaction graph's preprocessed data (fee, size, ancestors,...
const SetType & Ancestors(DepGraphIndex i) const noexcept
Get the ancestors of a given transaction i.
const FeeFrac & FeeRate(DepGraphIndex i) const noexcept
Get the feerate of a given transaction i.
DepGraphIndex AddTransaction(const FeeFrac &feefrac) noexcept
Add a new unconnected transaction to this transaction graph (in the first available position),...
const SetType & Descendants(DepGraphIndex i) const noexcept
Get the descendants of a given transaction i.
const SetType & Positions() const noexcept
Get the set of transactions positions in use.
Class to represent the internal state of the spanning-forest linearization (SFL) algorithm.
#define LIMITED_WHILE(condition, limit)
Can be used to limit a theoretically unbounded loop.
uint32_t DepGraphIndex
Data type to represent transaction indices in DepGraphs and the clusters they represent.
std::vector< FeeFrac > ChunkLinearization(const DepGraph< SetType > &depgraph, std::span< const DepGraphIndex > linearization) noexcept
Compute the feerates of the chunks of linearization.
std::tuple< std::vector< DepGraphIndex >, bool, uint64_t > Linearize(const DepGraph< SetType > &depgraph, uint64_t max_cost, uint64_t rng_seed, const StrongComparator< DepGraphIndex > auto &fallback_order, std::span< const DepGraphIndex > old_linearization={}, bool is_topological=true) noexcept
Find or improve a linearization for a cluster.
std::compare_three_way IndexTxOrder
Simple default transaction ordering function for SpanningForestState::GetLinearization() and Lineariz...
void PostLinearize(const DepGraph< SetType > &depgraph, std::span< DepGraphIndex > linearization)
Improve a given linearization.
std::vector< SetInfo< SetType > > ChunkLinearizationInfo(const DepGraph< SetType > &depgraph, std::span< const DepGraphIndex > linearization) noexcept
Compute the chunks of linearization as SetInfos.
Data structure storing a fee and size, ordered by increasing fee/size.
A set of transactions together with their aggregate feerate.
void Set(const DepGraph< SetType > &depgraph, DepGraphIndex pos) noexcept
Add a transaction to this SetInfo (which must not yet be in it).
static constexpr auto MAX_SIMPLE_ITERATIONS
std::partial_ordering CompareChunks(std::span< const FeeFrac > chunks0, std::span< const FeeFrac > chunks1)
Compare the feerate diagrams implied by the provided sorted chunks data.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.