QuickCppLib 0.10
Eliminate all the tedious hassle when making state-of-the-art C++ 14 - 23 libraries!
Loading...
Searching...
No Matches
prime_modulus.hpp File Reference
#include "../config.hpp"
#include <cstddef>
#include <cstdint>

Namespaces

namespace  quickcpplib
 The QuickCppLib namespace.
namespace  quickcpplib::_xxx
 Per commit unique namespace to prevent different git submodule versions clashing.
namespace  quickcpplib::_xxx::algorithm
namespace  quickcpplib::_xxx::algorithm::prime_modulus
namespace  quickcpplib::_xxx::algorithm::prime_modulus::detail

Functions

constexpr uint64_t quickcpplib::_xxx::algorithm::prime_modulus::twos_power_prime (std::size_t power) noexcept
 Returns a constexpr prime just under a twos power e.g. for 8, you get 251, which is the prime just below (1<<8) = 256. Very handy for hash tables.
template<uint32_t power, class T>
constexpr T quickcpplib::_xxx::algorithm::prime_modulus::detail::mod (T v)
template<class T>
constexpr T quickcpplib::_xxx::algorithm::prime_modulus::prime_modulus (T v, uint32_t power)
 Return the modulus of a number by the prime just below a twos power. Implemented as a fixed jump table, so the compiler can avoid the CPU division opcode, which still costs 40-90 CPU cycles, and excludes all CPU level parallelism.