7#include "../utility/utility.hpp"
8#include "../macros.hpp"
25template<
size_t BitsPerInteger,
size_t N>
30 constexpr static size_t bits_per_integer = BitsPerInteger;
36 constexpr static size_t store_size = ceil(bits_per_integer + CHAR_BIT - 1,
size_t{CHAR_BIT}) /
size_t{CHAR_BIT};
37 static_assert(
sizeof(
unsigned long long) >= store_size);
46 std::conditional_t<
sizeof(
unsigned char) >= store_size,
unsigned char,
47 std::conditional_t<
sizeof(
unsigned short) >= store_size,
unsigned short,
48 std::conditional_t<
sizeof(
unsigned int) >= store_size,
unsigned int,
49 std::conditional_t<
sizeof(
unsigned long) >= store_size,
unsigned long,
50 unsigned long long>>>>;
58 template<std::integral... Args>
63 [[nodiscard]]
constexpr size_t size() const noexcept
81 hilet offset = i * bits_per_integer;
82 hilet byte_offset = offset / CHAR_BIT;
83 hilet bit_offset = offset % CHAR_BIT;
85 return (unaligned_load<value_type>(_v.data() + byte_offset) >> bit_offset) & mask;
101 static_assert(I < N);
102 constexpr size_t offset = I * bits_per_integer;
103 constexpr size_t byte_offset = offset / CHAR_BIT;
104 constexpr size_t bit_offset = offset % CHAR_BIT;
106 return (load<value_type>(rhs._v.data() + byte_offset) >> bit_offset) & mask;
110 constexpr static size_t total_num_bits = bits_per_integer * N;
111 constexpr static size_t total_num_bytes = (total_num_bits + CHAR_BIT - 1) / CHAR_BIT;
112 constexpr static size_t mask = (1_uz << bits_per_integer) - 1;
123 template<std::integral... Args>
124 [[nodiscard]]
constexpr static array_type make_v(Args... args)
noexcept
126 static_assert(
sizeof...(Args) == N);
128 auto r = array_type{};
131 for (
auto i = 0_uz; i != N; ++i) {
132 hilet offset = i * bits_per_integer;
133 hilet byte_offset = offset / CHAR_BIT;
134 hilet bit_offset = offset % CHAR_BIT;
136 hilet arg = args_[i];
137 hi_axiom(arg <= mask);
138 store_or(arg << bit_offset, r.data() + byte_offset);
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr Out narrow_cast(In const &rhs) noexcept
Cast numeric values without loss of precision.
Definition cast.hpp:377
An array of integers.
Definition packed_int_array.hpp:26
constexpr size_t size() const noexcept
The number of integers stored in the array.
Definition packed_int_array.hpp:63
std::conditional_t< sizeof(unsigned char) >=store_size, unsigned char, std::conditional_t< sizeof(unsigned short) >=store_size, unsigned short, std::conditional_t< sizeof(unsigned int) >=store_size, unsigned int, std::conditional_t< sizeof(unsigned long) >=store_size, unsigned long, unsigned long long > > > > value_type
The value type of the unsigned integers that are stored in the array.
Definition packed_int_array.hpp:45
constexpr value_type operator[](size_t i) const noexcept
Get the integer at an index.
Definition packed_int_array.hpp:77
constexpr packed_int_array(Args... args) noexcept
Constructor of the array.
Definition packed_int_array.hpp:59
friend constexpr value_type get(packed_int_array const &rhs) noexcept
Get the integer at an index.
Definition packed_int_array.hpp:99