Bitcoin Core 31.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. More...

#include <feefrac.h>

Inheritance diagram for FeeFrac:
[legend]

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...
 
template<bool RoundDown>
int64_t EvaluateFee (int32_t at_size) const noexcept
 Compute the fee for a given size at_size using this object's feerate. More...
 
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. More...
 
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. More...
 

Static Public Member Functions

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. More...
 
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 positive infinity (if !round_down). More...
 

Public Attributes

int64_t fee
 
int32_t size
 

Static Public Attributes

static constexpr auto Mul = MulFallback
 
static constexpr auto Div = DivFallback
 

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...
 
void swap (FeeFrac &a, FeeFrac &b) noexcept
 Swap two FeeFracs. More...
 

Detailed Description

Data structure storing a fee and size.

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

Definition at line 21 of file feefrac.h.

Constructor & Destructor Documentation

◆ FeeFrac() [1/3]

constexpr FeeFrac::FeeFrac ( )
inlineconstexprnoexcept

Construct an IsEmpty() FeeFrac.

Definition at line 93 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 96 of file feefrac.h.

◆ FeeFrac() [3/3]

constexpr FeeFrac::FeeFrac ( const FeeFrac )
inlineconstexprdefaultnoexcept

Member Function Documentation

◆ DivFallback()

static int64_t FeeFrac::DivFallback ( std::pair< int64_t, uint32_t >  n,
int32_t  d,
bool  round_down 
)
inlinestaticnoexcept

Helper function for 96/32 signed division, rounding towards negative infinity (if round_down) or positive infinity (if !round_down).

This is a fallback version, separate so that it can be tested on platforms where it isn't actually needed.

The exact behavior with negative n does not really matter, but this implementation chooses to be consistent for testability reasons.

The result must fit in an int64_t, and d must be strictly positive.

Definition at line 41 of file feefrac.h.

Here is the caller graph for this function:

◆ EvaluateFee()

template<bool RoundDown>
int64_t FeeFrac::EvaluateFee ( int32_t  at_size) const
inlinenoexcept

Compute the fee for a given size at_size using this object's feerate.

This effectively corresponds to evaluating (this->fee * at_size) / this->size, with the result rounded towards negative infinity (if RoundDown) or towards positive infinity (if !RoundDown).

Requires this->size > 0, at_size >= 0, and that the correct result fits in a int64_t. This is guaranteed to be the case when 0 <= at_size <= this->size.

Definition at line 155 of file feefrac.h.

Here is the call graph for this function:

◆ EvaluateFeeDown()

int64_t FeeFrac::EvaluateFeeDown ( int32_t  at_size) const
inlinenoexcept

Compute the fee for a given size at_size using this object's feerate, rounding down.

Definition at line 174 of file feefrac.h.

Here is the caller graph for this function:

◆ EvaluateFeeUp()

int64_t FeeFrac::EvaluateFeeUp ( int32_t  at_size) const
inlinenoexcept

Compute the fee for a given size at_size using this object's feerate, rounding up.

Definition at line 176 of file feefrac.h.

Here is the caller graph for this function:

◆ IsEmpty()

bool FeeFrac::IsEmpty ( ) const
inlinenoexcept

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

Definition at line 102 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

Helper function for 32*64 signed multiplication, returning an unspecified but totally ordered type.

This is a fallback version, separate so it can be tested on platforms where it isn't actually needed.

Definition at line 26 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 107 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 114 of file feefrac.h.

◆ operator=()

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

Friends And Related Function Documentation

◆ operator+

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

Sum fee and size.

Definition at line 121 of file feefrac.h.

◆ operator-

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

Subtract both fee and size.

Definition at line 127 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 133 of file feefrac.h.

◆ swap

void swap ( FeeFrac a,
FeeFrac b 
)
friend

Swap two FeeFracs.

Definition at line 139 of file feefrac.h.

Member Data Documentation

◆ Div

constexpr auto FeeFrac::Div = DivFallback
staticconstexpr

Definition at line 86 of file feefrac.h.

◆ fee

int64_t FeeFrac::fee

Definition at line 89 of file feefrac.h.

◆ Mul

constexpr auto FeeFrac::Mul = MulFallback
staticconstexpr

Definition at line 85 of file feefrac.h.

◆ size

int32_t FeeFrac::size

Definition at line 90 of file feefrac.h.


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