14#include "../uint256/uint256.hpp"
18inline std::vector<uint64_t>
slice_input(
const uint256_t& input,
const uint64_t base,
const size_t num_slices)
21 std::vector<uint64_t> slices;
23 for (
size_t i = 0; i < num_slices; ++i) {
24 slices.push_back((target % base).
data[0]);
29 slices.push_back((target % base).
data[0]);
37 const std::vector<uint64_t>& bases)
40 std::vector<uint64_t> slices;
41 for (
size_t i = 0; i < bases.size(); ++i) {
42 if (target >= bases[i] && i == bases.size() - 1) {
45 slices.push_back((target % bases[i]).
data[0]);
55 for (
size_t i = 1; i < num_slices; ++i) {
56 output[i] = output[i - 1] * base;
64 auto converted = input;
66 constexpr auto base_powers = get_base_powers<base, 32>();
67 for (
size_t i = 0; i < 32; ++i) {
68 uint64_t sparse_bit = ((converted >> i) & 1U);
70 out += base_powers[i];
81 constexpr auto bases = get_base_powers<base, 32>();
83 for (uint64_t i = 0; i < 32; ++i) {
84 const auto& base_power = bases[
static_cast<size_t>(31 - i)];
86 for (uint64_t j = 1; j < base + 1; ++j) {
87 const auto threshold = prev_threshold + base_power;
88 if (target < threshold) {
89 bool bit = ((j - 1) & 1);
91 output += (1ULL << (31ULL - i));
94 target -= (prev_threshold);
98 prev_threshold = threshold;
110 for (
size_t i = 0; i < num_bits; ++i) {
111 const uint64_t bit = (input >> i) & 1U;
124 for (
size_t i = 0; i < num_bits - 1; ++i) {
125 result.
limbs[i] += other.limbs[i];
126 if (result.
limbs[i] >= base) {
127 result.
limbs[i] -= base;
128 ++result.
limbs[i + 1];
131 result.
limbs[num_bits - 1] += other.limbs[num_bits - 1];
132 result.
limbs[num_bits - 1] %= base;
133 result.
value += other.value;
139 *
this = *
this + other;
148 for (
size_t i = num_bits - 1; i < num_bits; --i) {
158 std::array<uint64_t, num_bits>
limbs;
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)
const std::vector< FF > data
constexpr uint64_t map_from_sparse_form(const uint256_t &input)
constexpr uint256_t map_into_sparse_form(const uint64_t input)
std::vector< uint64_t > slice_input(const uint256_t &input, const uint64_t base, const size_t num_slices)
constexpr std::array< uint256_t, num_slices > get_base_powers()
std::vector< uint64_t > slice_input_using_variable_bases(const uint256_t &input, const std::vector< uint64_t > &bases)
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept
void throw_or_abort(std::string const &err)