15#include "../uint256/uint256.hpp"
23inline std::vector<uint64_t>
slice_input(
const uint256_t& input,
const uint64_t base,
const size_t num_slices)
27 std::vector<uint64_t> slices;
29 slices.reserve(num_slices);
30 for (
size_t i = 0; i < num_slices; ++i) {
48 const std::vector<uint64_t>& bases)
51 std::vector<uint64_t> slices;
52 slices.reserve(bases.size());
53 for (
size_t i = 0; i < bases.size(); ++i) {
55 if (
target >= bases[i] && i == bases.size() - 1) {
71 for (
size_t i = 1; i < num_slices; ++i) {
72 output[i] = output[i - 1] * base;
85 auto converted = input;
87 constexpr auto base_powers = get_base_powers<base, 32>();
88 for (
size_t i = 0; i < 32; ++i) {
89 uint64_t sparse_bit = ((converted >> i) & 1U);
91 out += base_powers[i];
107 constexpr auto bases = get_base_powers<base, 32>();
109 for (uint64_t i = 0; i < 32; ++i) {
110 const auto& base_power = bases[
static_cast<size_t>(31 - i)];
112 for (uint64_t j = 1; j < base + 1; ++j) {
113 const auto threshold = prev_threshold + base_power;
115 bool bit = ((j - 1) & 1);
117 output += (1ULL << (31ULL - i));
120 target -= (prev_threshold);
124 prev_threshold = threshold;
142 for (
size_t i = 0; i < num_bits; ++i) {
143 const uint64_t bit = (input >> i) & 1U;
158 for (
size_t i = 0; i < num_bits - 1; ++i) {
159 result.limbs[i] += other.limbs[i];
160 if (
result.limbs[i] >= base) {
168 result.limbs[num_bits - 1] += other.limbs[num_bits - 1];
169 result.limbs[num_bits - 1] %= base;
170 result.value += other.value;
176 *
this = *
this + other;
185 for (
size_t i = num_bits - 1; i < num_bits; --i) {
195 std::array<uint64_t, num_bits>
limbs;
#define BB_ASSERT(expression,...)
Integer type that stores each bit as a separate digit in the given base. Supports addition with singl...
sparse_int & operator=(sparse_int &&other) noexcept=default
sparse_int & operator=(const sparse_int &other) noexcept=default
std::array< uint64_t, num_bits > limbs
sparse_int(const sparse_int &other) noexcept=default
uint64_t get_sparse_value() const
sparse_int(sparse_int &&other) noexcept=default
const std::array< uint64_t, num_bits > & get_limbs() const
uint64_t get_value() const
~sparse_int() noexcept=default
sparse_int(const uint64_t input=0)
sparse_int operator+=(const sparse_int &other)
std::string format(Args... args)
constexpr uint64_t map_from_sparse_form(const uint256_t &input)
Decode a sparse-form uint256_t back to a 32-bit value. Extracts the base-adic digits from most-signif...
constexpr uint256_t map_into_sparse_form(const uint64_t input)
Encode a 32-bit value into sparse form: each binary bit of input becomes a digit in the given base....
std::vector< uint64_t > slice_input(const uint256_t &input, const uint64_t base, const size_t num_slices)
Decompose a uint256_t into digits in the given base (least-significant digit first)....
constexpr std::array< uint256_t, num_slices > get_base_powers()
Compute [1, base, base^2, ..., base^(num_slices-1)] as uint256_t values.
std::vector< uint64_t > slice_input_using_variable_bases(const uint256_t &input, const std::vector< uint64_t > &bases)
Decompose a uint256_t using a different base for each digit position (least-significant first)....
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
std::vector< Instruction > target
bb::VectorAffineElementPushSpan< BaseParams > out
void throw_or_abort(std::string const &err)