MySQL 9.1.0
Source Code Documentation
ut::fast_modulo_t Class Reference

Allows to execute x % mod for a specified mod in a fast way, without using a slow operation of division. More...

#include <ut0math.h>

Public Member Functions

 fast_modulo_t ()=default
 
 fast_modulo_t (uint64_t mod)
 
 fast_modulo_t (uint64_t mod, uint64_t inv)
 
uint64_t compute (uint64_t x) const
 Computes the value of x % mod. More...
 
uint64_t get_inverse () const
 Gets the precomputed value of inverse. More...
 
uint64_t get_mod () const
 Gets the modulo value. More...
 

Static Public Member Functions

static uint64_t precompute_inv (uint64_t mod)
 Precomputes the inverse needed for fast modulo operations. More...
 

Private Attributes

uint64_t m_mod {0}
 
uint64_t m_inv {0}
 

Detailed Description

Allows to execute x % mod for a specified mod in a fast way, without using a slow operation of division.

The additional cost is hidden in constructor to preprocess the mod constant.

Constructor & Destructor Documentation

◆ fast_modulo_t() [1/3]

ut::fast_modulo_t::fast_modulo_t ( )
default

◆ fast_modulo_t() [2/3]

ut::fast_modulo_t::fast_modulo_t ( uint64_t  mod)
inlineexplicit

◆ fast_modulo_t() [3/3]

ut::fast_modulo_t::fast_modulo_t ( uint64_t  mod,
uint64_t  inv 
)
inlineexplicit

Member Function Documentation

◆ compute()

uint64_t ut::fast_modulo_t::compute ( uint64_t  x) const
inline

Computes the value of x % mod.

◆ get_inverse()

uint64_t ut::fast_modulo_t::get_inverse ( ) const
inline

Gets the precomputed value of inverse.

◆ get_mod()

uint64_t ut::fast_modulo_t::get_mod ( ) const
inline

Gets the modulo value.

◆ precompute_inv()

static uint64_t ut::fast_modulo_t::precompute_inv ( uint64_t  mod)
inlinestatic

Precomputes the inverse needed for fast modulo operations.

Member Data Documentation

◆ m_inv

uint64_t ut::fast_modulo_t::m_inv {0}
private

◆ m_mod

uint64_t ut::fast_modulo_t::m_mod {0}
private

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