Go to the documentation of this file.
9 #ifndef EAGINE_BIT_DENSITY_HPP
10 #define EAGINE_BIT_DENSITY_HPP
20 using double_byte = std::conditional_t<
23 std::conditional_t<(CHAR_BIT > 16), uint_fast32_t, uint_fast64_t>>;
25 static constexpr
auto byte_bits() noexcept {
32 return EAGINE_CONSTEXPR_ASSERT(
33 (bits >= 1) and (bits <= byte_bits()),
34 (((original_length * byte_bits()) / bits) +
35 (((original_length * byte_bits()) % bits) ? 1 : 0)));
41 return EAGINE_CONSTEXPR_ASSERT(
42 (bits >= 1) and (bits <= byte_bits()),
43 (((original_length * bits) / byte_bits()) +
44 (((original_length * bits) % byte_bits()) ? 1 : 0)));
47 template <
typename Getter,
typename Putter>
49 do_dissolve_bits(Getter get, Putter put,
span_size_t bits) noexcept ->
bool {
51 EAGINE_ASSERT(bits >= 1);
52 EAGINE_ASSERT(bits <= byte_bits());
56 const auto m =
byte((1U << bits) - 1U);
58 auto push = [&]() ->
bool {
60 if(!put(
byte(w >> double_byte(r - bits)) & m)) {
70 if(
auto src = get()) {
84 EAGINE_ASSERT(r < bits);
85 if(!put(
byte(w << double_byte(bits - r)) & m)) {
92 template <
typename Getter,
typename Putter>
94 do_concentrate_bits(Getter get, Putter put,
span_size_t bits) noexcept ->
bool {
95 EAGINE_ASSERT(bits >= 1);
96 EAGINE_ASSERT(bits <= byte_bits());
100 const double_byte m = (1U << bits) - 1U;
105 while(r < byte_bits()) {
106 if(
auto src = get()) {
109 w = (w & ~m) | (double_byte(
extract(src)) & m);
116 if(r >= byte_bits()) {
117 if(!put(
byte(w >> double_byte(r - byte_bits())))) {
128 #endif // EAGINE_BIT_DENSITY_HPP
std::ptrdiff_t span_size_t
Signed span size type used by eagine.
Definition: types.hpp:36
Common code is placed in this namespace.
Definition: eagine.hpp:21
static constexpr auto extract(api_result_value< Result, api_result_validity::never > &) noexcept -> Result &
Overload of extract for api_result_value.
Definition: c_api_wrap.hpp:270
unsigned char byte
Byte type alias.
Definition: types.hpp:24