13 const std::array<Span<const FeeFrac>, 2> chunk = {chunks0, chunks1};
15 size_t next_index[2] = {0, 0};
19 bool better_somewhere[2] = {
false,
false};
21 const auto next_point = [&](
int dia) {
return chunk[dia][next_index[dia]] + accum[dia]; };
23 const auto prev_point = [&](
int dia) {
return accum[dia]; };
25 const auto advance = [&](
int dia) { accum[dia] += chunk[dia][next_index[dia]++]; };
28 bool done_0 = next_index[0] == chunk[0].
size();
29 bool done_1 = next_index[1] == chunk[1].size();
30 if (done_0 && done_1)
break;
34 const int unproc_side = (done_0 || done_1) ? done_0 : next_point(0).size > next_point(1).size;
40 const FeeFrac& point_p = next_point(unproc_side);
41 const FeeFrac& point_a = prev_point(!unproc_side);
43 const auto slope_ap = point_p - point_a;
45 std::weak_ordering cmp = std::weak_ordering::equivalent;
46 if (done_0 || done_1) {
48 Assume(!(done_0 && done_1));
49 cmp = FeeRateCompare(slope_ap,
FeeFrac(0, 1));
52 const FeeFrac& point_b = next_point(!unproc_side);
53 const auto slope_ab = point_b - point_a;
54 Assume(slope_ab.size >= slope_ap.size);
55 cmp = FeeRateCompare(slope_ap, slope_ab);
59 if (point_b.
size == point_p.
size) advance(!unproc_side);
63 if (std::is_gt(cmp)) better_somewhere[unproc_side] =
true;
64 if (std::is_lt(cmp)) better_somewhere[!unproc_side] =
true;
68 if (better_somewhere[0] && better_somewhere[1])
return std::partial_ordering::unordered;
72 return better_somewhere[0] <=> better_somewhere[1];
#define Assume(val)
Assume is the identity function.
A Span is an object that can refer to a contiguous sequence of objects.
Data structure storing a fee and size, ordered by increasing fee/size.
std::partial_ordering CompareChunks(Span< const FeeFrac > chunks0, Span< const FeeFrac > chunks1)
Compare the feerate diagrams implied by the provided sorted chunks data.