7#include "../utility/utility.hpp"
8#include "../macros.hpp"
16namespace hi::inline
v1 {
25template<
size_t BitsPerInteger,
size_t N>
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
82 hilet byte_offset = offset / CHAR_BIT;
83 hilet bit_offset = offset % CHAR_BIT;
101 static_assert(I < N);
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);
145template<
size_t BitsPerInteger, std::unsigned_integral... Args>
146packed_int_array(Args...) -> packed_int_array<BitsPerInteger,
sizeof...(Args)>;
DOXYGEN BUG.
Definition algorithm.hpp:16
constexpr T ceil(T value, T alignment) noexcept
The smallest multiple of alignment greater than or equal to value.
Definition math.hpp:130
constexpr T unaligned_load(B const *src) noexcept
Make an unaligned load of an unsigned integer.
Definition memory.hpp:271
constexpr size_t size() const noexcept
The number of integers stored in the array.
Definition packed_int_array.hpp:63
constexpr value_type operator[](size_t i) const noexcept
Get the integer at an index.
Definition packed_int_array.hpp:77
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
static constexpr size_t bits_per_integer
Number of bits of the unsigned integer.
Definition packed_int_array.hpp:30
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
static constexpr size_t store_size
Number of bytes required to hold the number of bits.
Definition packed_int_array.hpp:36