12std::partial_ordering
CompareChunks(std::span<const FeeFrac> chunks0, std::span<const FeeFrac> chunks1)
15 const std::array<std::span<const FeeFrac>, 2> chunk = {chunks0, chunks1};
17 size_t next_index[2] = {0, 0};
21 bool better_somewhere[2] = {
false,
false};
23 const auto next_point = [&](
int dia) {
return chunk[dia][next_index[dia]] + accum[dia]; };
25 const auto prev_point = [&](
int dia) {
return accum[dia]; };
27 const auto advance = [&](
int dia) { accum[dia] += chunk[dia][next_index[dia]++]; };
30 bool done_0 = next_index[0] == chunk[0].
size();
31 bool done_1 = next_index[1] == chunk[1].size();
32 if (done_0 && done_1)
break;
36 const int unproc_side = (done_0 || done_1) ? done_0 : next_point(0).size > next_point(1).size;
42 const FeeFrac& point_p = next_point(unproc_side);
43 const FeeFrac& point_a = prev_point(!unproc_side);
45 const auto slope_ap = point_p - point_a;
47 std::weak_ordering cmp = std::weak_ordering::equivalent;
48 if (done_0 || done_1) {
50 Assume(!(done_0 && done_1));
51 cmp = FeeRateCompare(slope_ap,
FeeFrac(0, 1));
54 const FeeFrac& point_b = next_point(!unproc_side);
55 const auto slope_ab = point_b - point_a;
56 Assume(slope_ab.size >= slope_ap.size);
57 cmp = FeeRateCompare(slope_ap, slope_ab);
61 if (point_b.
size == point_p.
size) advance(!unproc_side);
65 if (std::is_gt(cmp)) better_somewhere[unproc_side] =
true;
66 if (std::is_lt(cmp)) better_somewhere[!unproc_side] =
true;
70 if (better_somewhere[0] && better_somewhere[1])
return std::partial_ordering::unordered;
74 return better_somewhere[0] <=> better_somewhere[1];
#define Assume(val)
Assume is the identity function.
Data structure storing a fee and size, ordered by increasing fee/size.
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.