38#include <gtest/gtest.h>
67 istringstream
in(
out.str());
71 for (
size_t i = 0; i <
parsed.num_bytes; ++i)
75 parsed.bytes.push_back(value);
83 out.reserve(bits.size());
93 out.reserve(num_bits);
94 for (
size_t i = 0; i < num_bits; ++i)
96 const size_t shift = num_bits - i - 1;
97 const bool bit = ((value >>
shift) &
U(1)) != 0;
98 out.push_back(
bit ?
'1' :
'0');
106 using U = std::make_unsigned_t<T>;
107 const U u =
static_cast<U>(value);
116 for (
size_t i = 0; i < n; ++i)
117 bits.push_back(dist(
rng) ? 1u : 0u);
124 for (
size_t i = 0; i < bits.size(); ++i)
133 const size_t n =
max(a.size(), b.size());
135 for (
size_t i = 0; i < n; ++i)
137 const unsigned int lhs = i < a.
size() ? a[i] : 0u;
138 const unsigned int rhs = i < b.
size() ? b[i] : 0u;
147 const size_t n =
min(a.size(), b.size());
149 for (
size_t i = 0; i < n; ++i)
150 out[i] = a[i] & b[i];
162 for (
size_t i = 0; i < a.size(); ++i)
174 static_assert(
sizeof(
Byte) == 1);
298 istringstream
in(
out.str());
314 bytes.reserve(
saved.num_bytes);
315 for (
int value :
saved.bytes)
337 dyn.dyn_left_shift(2);
339 dyn.dyn_right_shift(2);
385 for (
size_t i = 9; i < 16; ++i)
393 for (
size_t i = 9; i < 16; ++i)
400 const unsigned char bytes[] = {0x00, 0xFF};
402 rhs.load_from_array_of_chars(bytes, 9);
409 for (
size_t i = 9; i < 16; ++i)
418 for (
size_t i = 9; i < 16; ++i)
428 for (
size_t i = 9; i < 15; ++i)
451 bool operator()(
int bit)
531 constexpr size_t ul_bits =
sizeof(
unsigned long) * 8;
532 constexpr size_t extra = 5;
546 const size_t n1 =
rng() % 200;
547 const size_t n2 =
rng() % 200;
643 auto it = list.get_it();
Space-efficient bit array implementation.
unsigned int get_curr_ne() const 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.
std::string get_bit_str() const
void circular_left_shift(const size_t n=1)
Shifts the bits n positions to the left circularly.
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.
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.
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 write_bit(const size_t i, const unsigned int value)
Write bit i with the value.
void reserve(const size_t dim)
Reserve memory in advance for the bit array dim dimension.
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.
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.
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
void save(std::ostream &output) const
Saves the bit sequence in a text file.
unsigned long get_unum() const noexcept
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
int count_ones() const noexcept
void set_int(int i) noexcept
unsigned int read_bit(const unsigned int i) const noexcept
int count_zeros() const noexcept
size_t size() const noexcept
Count the number of elements of the list.
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_max_function > > max(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
__gmp_expr< typename __gmp_resolve_expr< T, V >::value_type, __gmp_binary_expr< __gmp_expr< T, U >, __gmp_expr< V, W >, __gmp_min_function > > min(const __gmp_expr< T, U > &expr1, const __gmp_expr< V, W > &expr2)
Main namespace for Aleph-w library functions.
bool completed() const noexcept
Return true if all underlying iterators are finished.
T & swap(T &t1, T &t2)
Generic swap using object's swap method.
std::decay_t< typename HeadC::Item_Type > T
DynList< T > maps(const C &c, Op op)
Classic map operation.