106# include <type_traits>
123 return (
value >> i) & 0x1;
126 void write_bit(
const unsigned int i,
const unsigned int val)
noexcept
130 const std::uint8_t mask =
static_cast<std::uint8_t
>(1) << i;
131#ifdef __cpp_lib_atomic_ref
132 std::atomic_ref<std::uint8_t>
atm_val(this->value);
134 atm_val.fetch_or(mask, std::memory_order_relaxed);
136 atm_val.fetch_and(
static_cast<std::uint8_t
>(~mask), std::memory_order_relaxed);
150 return static_cast<int>(
value);
155 value =
static_cast<std::uint8_t
>(i);
172 return std::popcount(
value);
326 for (
size_t i = 0; i <
dim; ++i)
374 const unsigned int bit_index =
static_cast<unsigned int>(i % 8);
377 const Byte &
byte = *ptr;
427 const int bit_index = i % 8;
569 for (
size_t i = 0; i < num_bytes; ++i)
576 if (num_bytes != 0 && i + 1 == num_bytes)
579 const int mask = (1u <<
used) - 1u;
585 <<
"BitArray::save: write payload failed (byte " << i <<
")";
605 size_t num_bytes = 0;
610 const size_t expected = (num_bits + 7) / 8;
612 <<
"BitArray::load: inconsistent header (num_bytes vs num_bits)";
617 tmp.array_of_bytes.cut();
618 tmp.ensure_num_bytes(num_bytes);
620 for (
size_t i = 0; i < num_bytes; ++i)
626 tmp.array_of_bytes.touch(i).set_int(
static_cast<int>(v));
629 tmp.clear_unused_bits_in_last_byte();
660 <<
"const unsigned char " << name <<
" [" << num_bytes <<
"] = {"
663 for (
size_t i = 0; i < num_bytes; i++)
669 if (num_bytes != 0 && i + 1 == num_bytes)
672 const int mask = (1u <<
used) - 1u;
678 if (i != num_bytes - 1)
681 if ((i + 1) % 15 == 0)
685 output <<
'\n' <<
"};" <<
'\n' <<
'\n';
700 const size_t num_bits)
704 size_t num_bytes = num_bits / 8;
706 if (num_bits % 8 != 0)
709 for (
size_t i = 0; i < num_bytes; i++)
748 for (
size_t i =
real_n; i > 0; --i)
761 for (
size_t i = 0; i < n; ++i)
812 for (
size_t i = 0; i <
real_n; ++i)
818 for (
size_t i = 0; i <
real_n; ++i)
847 for (
size_t i = 0; i <
real_n; ++i)
851 template <
typename T>
854 using U = std::make_unsigned_t<T>;
855 U u =
static_cast<U>(n);
857 const size_t num_bits =
sizeof(
T) * 8;
859 for (
size_t i = 0; i < num_bits; ++i)
893 for (
size_t i = 0; i < n; ++i)
900 return static_cast<long>(
get_unum());
906 const size_t &
str_size = str.size();
910 for (
size_t i = 0; i <
str_size; ++i)
941 BitArray(
const unsigned char str[],
const size_t num_bits)
969 if (
masked.get_int() == 0)
988 for (
size_t i = 0; i < num_bytes; ++i)
1023 for (
size_t i = 0; i <
size(); ++i)
1031 template <
class Operation>
1069 <<
"Iterator is at the end of the list";
1081 <<
"not current item in iterator";
1119 template <
class Operation>
1125 template <
class Operation>
1131 template <
class Operation>
1137 template <
class Operation>
CRTP Mixins for container functionality (DRY principle).
Exception handling system with formatted messages for Aleph-w.
#define ah_out_of_range_error_if(C)
Throws std::out_of_range if condition holds.
#define ah_underflow_error_if(C)
Throws std::underflow_error if condition holds.
#define ah_overflow_error_if(C)
Throws std::overflow_error if condition holds.
#define ah_runtime_error_if(C)
Throws std::runtime_error if condition holds.
DRY (Don't Repeat Yourself) utilities and macros.
#define Generic_Items(Type)
Generates an items() method returning all container elements.
#define STL_ALEPH_ITERATOR(Set_Name)
Core header for the Aleph-w library.
size_t size_t int32_t value
size_t size_t int32_t * out
BitProxy(BitArray &a, const size_t i) noexcept
BitProxy & operator=(const BitProxy &proxy)
BitProxy & operator=(const size_t value)
void reset_first() noexcept
unsigned int get_curr_ne() const noexcept
Iterator(const BitArray &array) noexcept
unsigned int get_curr() const
bool has_curr() const noexcept
long get_pos() const noexcept
void reset_last() noexcept
Contiguous array of bits.
bool traverse(Operation &operation) const
void fast_write(const size_t i, const unsigned int value)
int read_bit(const size_t i) const
Read bit i.
bool traverse(Operation &&operation=Operation()) const
void set_num(const short &c)
std::string get_bit_str() const
BitArray & operator=(BitArray &&array) noexcept
BitArray & operator&=(const BitArray &rhs)
void circular_left_shift(const size_t n=1)
Shifts the bits n positions to the left circularly.
BitArray(const unsigned char str[], const size_t num_bits)
Constructs a new array of bits from an array of characters previously generated with load_from_array_...
BitProxy operator[](const size_t i) noexcept
void set_num(const char &c)
void load_from_array_of_chars(const unsigned char str[], const size_t num_bits)
Reads an array of bits saved in a character array.
bool __traverse(Operation &operation)
bool operator==(const BitArray &rhs) const
long get_num() const noexcept
void set_bit_str(const std::string &str)
int fast_read(const size_t i) const noexcept
void write(const size_t i, const unsigned int value)
Writes bit i with value without memory check.
auto get_it() const noexcept
void left_shift(const size_t n=1)
Shifts the bits n positions to the left.
BitArray(const BitArray &array)
Copy constructor.
void circular_right_shift(const size_t n=1)
Shifts the bits n positions to the right circularly.
void pop()
Removes the last bit of the array.
void set_num(const long &c)
void write_bit(const size_t i, const unsigned int value)
Write bit i with the value.
BitArray(const size_t dim, const unsigned int value)
Build a BitArray of size dim with all bits set to value.
void reserve(const size_t dim)
Reserve memory in advance for the bit array dim dimension.
void dyn_left_shift(const size_t n=1)
Shifts bits n positions to the left dynamically.
BitArray & operator|=(const BitArray &rhs)
BitArray(const size_t dim=0)
Bit array constructor.
void right_shift(const size_t n=1)
Shifts the bits n positions to the right.
void load(std::istream &input)
Loads an array of bits from a file.
DynList< char > bits_list() const
Converts it to a list.
void empty() noexcept
Delete all inserted bits.
BitArray(BitArray &&array) noexcept
int count_ones() const noexcept
size_t get_num_bytes() const noexcept
void save_in_array_of_chars(const std::string &name, std::ostream &output) const
Saves a static string declaration to a text file.
int read(const size_t i) const
Quick read of bit i.
friend BitArray operator&(const BitArray &op1, const BitArray &op2)
friend std::ostream & operator<<(std::ostream &out, const BitArray &array)
void ensure_num_bytes(const size_t num_bytes)
BitArray(std::ifstream &input)
Build a new array of bits from a file constructed using the save() method.
void push(const unsigned int value)
Inserts the value at the end of the array.
constexpr size_t size() const noexcept
Returns the dimension of the bit array.
void swap(BitArray &array) noexcept
BitArray & operator=(const BitArray &array)
Bit array allocation.
void dyn_right_shift(const size_t n=1)
Shifts bits n positions to the right dynamically.
void set_num(const int &c)
friend BitArray operator|(const BitArray &op1, const BitArray &op2)
int operator()(const size_t i) const
bool traverse(Operation &operation)
bool traverse(Operation &&operation=Operation())
void save(std::ostream &output) const
Saves the bit sequence in a text file.
int count_zeros() const noexcept
int read_bit_ne(const size_t i) const noexcept
void clear_unused_bits_in_last_byte() noexcept
unsigned int Item_Type
Type returned by Iterator::get_curr() - individual bits as unsigned int.
unsigned long get_unum() const noexcept
std::string to_string() const
DynArray< Byte > array_of_bytes
int operator[](const size_t i) const
void set_size(const size_t sz)
Resets the dimension of the array.
void write_bit(const unsigned int i, const unsigned int val) noexcept
int get_int() const noexcept
Byte & operator|=(const Byte &rhs) noexcept
int count_ones() const noexcept
void set_int(int i) noexcept
unsigned int read_bit(const unsigned int i) const noexcept
Byte & operator&=(const Byte &rhs) noexcept
int count_zeros() const noexcept
Doubly-linked list (defined in tpl_dynList.H).
T & append(const T &item)
CRTP Mixin providing functional programming operations.
Minimal std::expected-style result type for C++20.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_dim_function > > dim(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
and
Check uniqueness with explicit hash + equality functors.
std::decay_t< typename HeadC::Item_Type > T
Lazy and scalable dynamic array implementation.