15namespace hi::inline
v1 {
24template<
size_t BitsPerInteger,
size_t N>
29 constexpr static size_t bits_per_integer = BitsPerInteger;
35 constexpr static size_t store_size = ceil(bits_per_integer + CHAR_BIT - 1,
size_t{CHAR_BIT}) /
size_t{CHAR_BIT};
36 static_assert(
sizeof(
unsigned long long) >= store_size);
45 std::conditional_t<
sizeof(
unsigned char) >= store_size,
unsigned char,
46 std::conditional_t<
sizeof(
unsigned short) >= store_size,
unsigned short,
47 std::conditional_t<
sizeof(
unsigned int) >= store_size,
unsigned int,
48 std::conditional_t<
sizeof(
unsigned long) >= store_size,
unsigned long,
49 unsigned long long>>>>;
57 template<std::integral... Args>
62 [[nodiscard]]
constexpr size_t size() const noexcept
80 hilet offset = i * bits_per_integer;
81 hilet byte_offset = offset / CHAR_BIT;
82 hilet bit_offset = offset % CHAR_BIT;
84 return (load<value_type>(_v.data() + byte_offset) >> bit_offset) & mask;
100 static_assert(I < N);
101 constexpr size_t offset = I * bits_per_integer;
102 constexpr size_t byte_offset = offset / CHAR_BIT;
103 constexpr size_t bit_offset = offset % CHAR_BIT;
105 return (load<value_type>(rhs._v.data() + byte_offset) >> bit_offset) & mask;
109 constexpr static size_t total_num_bits = bits_per_integer * N;
110 constexpr static size_t total_num_bytes = (total_num_bits + CHAR_BIT - 1) / CHAR_BIT;
111 constexpr static size_t mask = (1_uz << bits_per_integer) - 1;
122 template<std::integral... Args>
123 [[nodiscard]]
constexpr static array_type make_v(Args... args)
noexcept
125 static_assert(
sizeof...(Args) == N);
127 auto r = array_type{};
130 for (
auto i = 0_uz; i != N; ++i) {
131 hilet offset = i * bits_per_integer;
132 hilet byte_offset = offset / CHAR_BIT;
133 hilet bit_offset = offset % CHAR_BIT;
135 hilet arg = args_[i];
137 store_or(
static_cast<value_type
>(arg << bit_offset), r.data() + byte_offset);
144template<
size_t BitsPerInteger, std::unsigned_integral... Args>
145packed_int_array(Args...) -> packed_int_array<BitsPerInteger,
sizeof...(Args)>;
#define hi_axiom(expression,...)
Specify an axiom; an expression that is true.
Definition assert.hpp:133
Miscellaneous math functions.
Utilities used by the HikoGUI library itself.
#define hilet
Invariant should be the default for variables.
Definition utility.hpp:23
DOXYGEN BUG.
Definition algorithm.hpp:15
An array of integers.
Definition packed_int_array.hpp:25
constexpr size_t size() const noexcept
The number of integers stored in the array.
Definition packed_int_array.hpp:62
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:44
constexpr value_type operator[](size_t i) const noexcept
Get the integer at an index.
Definition packed_int_array.hpp:76
constexpr packed_int_array(Args... args) noexcept
Constructor of the array.
Definition packed_int_array.hpp:58
friend constexpr value_type get(packed_int_array const &rhs) noexcept
Get the integer at an index.
Definition packed_int_array.hpp:98