Bitcoin Core 28.99.0
P2P Digital Currency
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Friends | List of all members
FeeFrac Struct Reference

Data structure storing a fee and size, ordered by increasing fee/size. More...

#include <feefrac.h>

Public Member Functions

constexpr FeeFrac () noexcept
 Construct an IsEmpty() FeeFrac. More...
 
constexpr FeeFrac (int64_t f, int32_t s) noexcept
 Construct a FeeFrac with specified fee and size. More...
 
constexpr FeeFrac (const FeeFrac &) noexcept=default
 
constexpr FeeFracoperator= (const FeeFrac &) noexcept=default
 
bool IsEmpty () const noexcept
 Check if this is empty (size and fee are 0). More...
 
void operator+= (const FeeFrac &other) noexcept
 Add fee and size of another FeeFrac to this one. More...
 
void operator-= (const FeeFrac &other) noexcept
 Subtract fee and size of another FeeFrac from this one. More...
 

Static Public Member Functions

static std::pair< int64_t, uint32_t > MulFallback (int64_t a, int32_t b) noexcept
 Fallback version for Mul (see below). More...
 

Public Attributes

int64_t fee
 
int32_t size
 

Static Public Attributes

static constexpr auto Mul = MulFallback
 

Friends

FeeFrac operator+ (const FeeFrac &a, const FeeFrac &b) noexcept
 Sum fee and size. More...
 
FeeFrac operator- (const FeeFrac &a, const FeeFrac &b) noexcept
 Subtract both fee and size. More...
 
bool operator== (const FeeFrac &a, const FeeFrac &b) noexcept
 Check if two FeeFrac objects are equal (both same fee and same size). More...
 
std::weak_ordering FeeRateCompare (const FeeFrac &a, const FeeFrac &b) noexcept
 Compare two FeeFracs just by feerate. More...
 
bool operator<< (const FeeFrac &a, const FeeFrac &b) noexcept
 Check if a FeeFrac object has strictly lower feerate than another. More...
 
bool operator>> (const FeeFrac &a, const FeeFrac &b) noexcept
 Check if a FeeFrac object has strictly higher feerate than another. More...
 
std::strong_ordering operator<=> (const FeeFrac &a, const FeeFrac &b) noexcept
 Compare two FeeFracs. More...
 
void swap (FeeFrac &a, FeeFrac &b) noexcept
 Swap two FeeFracs. More...
 

Detailed Description

Data structure storing a fee and size, ordered by increasing fee/size.

The size of a FeeFrac cannot be zero unless the fee is also zero.

FeeFracs have a total ordering, first by increasing feerate (ratio of fee over size), and then by decreasing size. The empty FeeFrac (fee and size both 0) sorts last. So for example, the following FeeFracs are in sorted order:

A FeeFrac is considered "better" if it sorts after another, by this ordering. All standard comparison operators (<=>, ==, !=, >, <, >=, <=) respect this ordering.

The FeeRateCompare, and >> and << operators only compare feerate and treat equal feerate but different size as equivalent. The empty FeeFrac is neither lower or higher in feerate than any other.

Definition at line 38 of file feefrac.h.

Constructor & Destructor Documentation

◆ FeeFrac() [1/3]

constexpr FeeFrac::FeeFrac ( )
inlineconstexprnoexcept

Construct an IsEmpty() FeeFrac.

Definition at line 67 of file feefrac.h.

◆ FeeFrac() [2/3]

constexpr FeeFrac::FeeFrac ( int64_t  f,
int32_t  s 
)
inlineconstexprnoexcept

Construct a FeeFrac with specified fee and size.

Definition at line 70 of file feefrac.h.

◆ FeeFrac() [3/3]

constexpr FeeFrac::FeeFrac ( const FeeFrac )
inlineconstexprdefaultnoexcept

Member Function Documentation

◆ IsEmpty()

bool FeeFrac::IsEmpty ( ) const
inlinenoexcept

Check if this is empty (size and fee are 0).

Definition at line 76 of file feefrac.h.

Here is the caller graph for this function:

◆ MulFallback()

static std::pair< int64_t, uint32_t > FeeFrac::MulFallback ( int64_t  a,
int32_t  b 
)
inlinestaticnoexcept

Fallback version for Mul (see below).

Separate to permit testing on platforms where it isn't actually needed.

Definition at line 44 of file feefrac.h.

Here is the caller graph for this function:

◆ operator+=()

void FeeFrac::operator+= ( const FeeFrac other)
inlinenoexcept

Add fee and size of another FeeFrac to this one.

Definition at line 81 of file feefrac.h.

◆ operator-=()

void FeeFrac::operator-= ( const FeeFrac other)
inlinenoexcept

Subtract fee and size of another FeeFrac from this one.

Definition at line 88 of file feefrac.h.

◆ operator=()

constexpr FeeFrac & FeeFrac::operator= ( const FeeFrac )
inlineconstexprdefaultnoexcept

Friends And Related Function Documentation

◆ FeeRateCompare

std::weak_ordering FeeRateCompare ( const FeeFrac a,
const FeeFrac b 
)
friend

Compare two FeeFracs just by feerate.

Definition at line 113 of file feefrac.h.

◆ operator+

FeeFrac operator+ ( const FeeFrac a,
const FeeFrac b 
)
friend

Sum fee and size.

Definition at line 95 of file feefrac.h.

◆ operator-

FeeFrac operator- ( const FeeFrac a,
const FeeFrac b 
)
friend

Subtract both fee and size.

Definition at line 101 of file feefrac.h.

◆ operator<<

bool operator<< ( const FeeFrac a,
const FeeFrac b 
)
friend

Check if a FeeFrac object has strictly lower feerate than another.

Definition at line 120 of file feefrac.h.

◆ operator<=>

std::strong_ordering operator<=> ( const FeeFrac a,
const FeeFrac b 
)
friend

Compare two FeeFracs.

<, >, <=, and >= are auto-generated from this.

Definition at line 134 of file feefrac.h.

◆ operator==

bool operator== ( const FeeFrac a,
const FeeFrac b 
)
friend

Check if two FeeFrac objects are equal (both same fee and same size).

Definition at line 107 of file feefrac.h.

◆ operator>>

bool operator>> ( const FeeFrac a,
const FeeFrac b 
)
friend

Check if a FeeFrac object has strictly higher feerate than another.

Definition at line 127 of file feefrac.h.

◆ swap

void swap ( FeeFrac a,
FeeFrac b 
)
friend

Swap two FeeFracs.

Definition at line 142 of file feefrac.h.

Member Data Documentation

◆ fee

int64_t FeeFrac::fee

Definition at line 63 of file feefrac.h.

◆ Mul

constexpr auto FeeFrac::Mul = MulFallback
staticconstexpr

Definition at line 60 of file feefrac.h.

◆ size

int32_t FeeFrac::size

Definition at line 64 of file feefrac.h.


The documentation for this struct was generated from the following file: