5#ifndef BITCOIN_UTIL_FEEFRAC_H
6#define BITCOIN_UTIL_FEEFRAC_H
44 static inline std::pair<int64_t, uint32_t>
MulFallback(int64_t a, int32_t b)
noexcept
47 int64_t low = int64_t{
static_cast<uint32_t
>(a)} * b;
48 int64_t high = (a >> 32) * b;
49 return {high + (low >> 32),
static_cast<uint32_t
>(low)};
53#ifdef __SIZEOF_INT128__
54 static inline __int128
Mul(int64_t a, int32_t b)
noexcept
57 return __int128{a} * b;
97 return {a.
fee + b.fee, a.size + b.size};
103 return {a.
fee - b.fee, a.size - b.size};
109 return a.fee == b.fee && a.size == b.size;
115 auto cross_a =
Mul(a.fee, b.size), cross_b =
Mul(b.fee, a.size);
116 return cross_a <=> cross_b;
122 auto cross_a =
Mul(a.fee, b.size), cross_b =
Mul(b.fee, a.size);
123 return cross_a < cross_b;
129 auto cross_a =
Mul(a.fee, b.size), cross_b =
Mul(b.fee, a.size);
130 return cross_a > cross_b;
136 auto cross_a =
Mul(a.fee, b.size), cross_b =
Mul(b.fee, a.size);
137 if (cross_a == cross_b)
return b.size <=> a.size;
138 return cross_a <=> cross_b;
144 std::swap(a.fee, b.fee);
145 std::swap(a.size, b.size);
A Span is an object that can refer to a contiguous sequence of objects.
std::partial_ordering CompareChunks(Span< const FeeFrac > chunks0, Span< const FeeFrac > chunks1)
Compare the feerate diagrams implied by the provided sorted chunks data.
Data structure storing a fee and size, ordered by increasing fee/size.
constexpr FeeFrac(int64_t f, int32_t s) noexcept
Construct a FeeFrac with specified fee and size.
friend std::weak_ordering FeeRateCompare(const FeeFrac &a, const FeeFrac &b) noexcept
Compare two FeeFracs just by feerate.
friend FeeFrac operator-(const FeeFrac &a, const FeeFrac &b) noexcept
Subtract both fee and size.
friend bool operator>>(const FeeFrac &a, const FeeFrac &b) noexcept
Check if a FeeFrac object has strictly higher feerate than another.
friend void swap(FeeFrac &a, FeeFrac &b) noexcept
Swap two FeeFracs.
friend std::strong_ordering operator<=>(const FeeFrac &a, const FeeFrac &b) noexcept
Compare two FeeFracs.
constexpr FeeFrac(const FeeFrac &) noexcept=default
constexpr FeeFrac & operator=(const FeeFrac &) noexcept=default
static constexpr auto Mul
friend bool operator<<(const FeeFrac &a, const FeeFrac &b) noexcept
Check if a FeeFrac object has strictly lower feerate than another.
void operator-=(const FeeFrac &other) noexcept
Subtract fee and size of another FeeFrac from this one.
void operator+=(const FeeFrac &other) noexcept
Add fee and size of another FeeFrac to this one.
bool IsEmpty() const noexcept
Check if this is empty (size and fee are 0).
constexpr FeeFrac() noexcept
Construct an IsEmpty() FeeFrac.
static std::pair< int64_t, uint32_t > MulFallback(int64_t a, int32_t b) noexcept
Fallback version for Mul (see below).
friend FeeFrac operator+(const FeeFrac &a, const FeeFrac &b) noexcept
Sum fee and size.
friend bool operator==(const FeeFrac &a, const FeeFrac &b) noexcept
Check if two FeeFrac objects are equal (both same fee and same size).