5#ifndef BITCOIN_UTIL_FEEFRAC_H
6#define BITCOIN_UTIL_FEEFRAC_H
80#ifdef __SIZEOF_INT128__
141 return {
a.
fee + b.fee,
a.size + b.size};
147 return {
a.
fee - b.fee,
a.size - b.size};
153 return a.fee == b.fee &&
a.size == b.size;
188 std::swap(
a.fee, b.fee);
189 std::swap(
a.size, b.size);
201 template<
bool RoundDown>
237template<
typename Tag>
#define Assume(val)
Assume is the identity function.
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.
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.
int64_t EvaluateFeeDown(int32_t at_size) const noexcept
Compute the fee for a given size at_size using this object's feerate, rounding down.
int64_t EvaluateFee(int32_t at_size) const noexcept
Compute the fee for a given size at_size using this object's feerate.
static int64_t DivFallback(std::pair< int64_t, uint32_t > n, int32_t d, bool round_down) noexcept
Helper function for 96/32 signed division, rounding towards negative infinity (if round_down) or posi...
int64_t EvaluateFeeUp(int32_t at_size) const noexcept
Compute the fee for a given size at_size using this object's feerate, rounding up.
friend std::strong_ordering operator<=>(const FeeFrac &a, const FeeFrac &b) noexcept
Compare two FeeFracs.
constexpr FeeFrac(const FeeFrac &) noexcept=default
static constexpr auto Div
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
Helper function for 32*64 signed multiplication, returning an unspecified but totally ordered type.
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).
Tagged wrapper around FeeFrac to avoid unit confusion.
static FeePerUnit FromFeeFrac(const FeeFrac &feefrac) noexcept
Convert a FeeFrac to a FeePerUnit.
constexpr auto Ticks(Dur2 d)
Helper to count the seconds of a duration/time_point.