Aleph-w 7.10.0
A C++ Library for Data Structures and Algorithms
Loading...
Searching...
No Matches
Aleph::BitArray Class Reference

Contiguous array of bits. More...

#include <bitArray.H>

Inheritance diagram for Aleph::BitArray:
[legend]
Collaboration diagram for Aleph::BitArray:
[legend]

Classes

class  BitProxy
 
class  Iterator
 

Public Types

using Item_Type = unsigned int
 Type returned by Iterator::get_curr() - individual bits as unsigned int.
 
using iterator = __iterator< BitArray >
 
using const_iterator = __const_iterator< BitArray >
 

Public Member Functions

 BitArray (const size_t dim=0)
 Bit array constructor.
 
 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.
 
constexpr size_t size () const noexcept
 Returns the dimension of the bit array.
 
void set_size (const size_t sz)
 Resets the dimension of the array.
 
int operator[] (const size_t i) const
 
BitProxy operator[] (const size_t i) noexcept
 
int read_bit_ne (const size_t i) const noexcept
 
int read_bit (const size_t i) const
 Read bit i.
 
int operator() (const size_t i) const
 
void write_bit (const size_t i, const unsigned int value)
 Write bit i with the value.
 
int read (const size_t i) const
 Quick read of bit i.
 
void write (const size_t i, const unsigned int value)
 Writes bit i with value without memory check.
 
int fast_read (const size_t i) const noexcept
 Read bit i without any check.
 
void fast_write (const size_t i, const unsigned int value)
 Write bit i without checking i.
 
void push (const unsigned int value)
 Inserts the value at the end of the array.
 
void pop ()
 Removes the last bit of the array.
 
void empty () noexcept
 Delete all inserted bits.
 
 BitArray (const BitArray &array)
 Copy constructor.
 
void swap (BitArray &array) noexcept
 
 BitArray (BitArray &&array) noexcept
 Move constructor; it allocates nothing.
 
BitArray & operator= (BitArray &&array) noexcept
 
DynList< char > bits_list () const
 Converts it to a list.
 
BitArray & operator= (const BitArray &array)
 Bit array allocation.
 
void save (std::ostream &output) const
 Saves the bit sequence in a text file.
 
void load (std::istream &input)
 Loads an array of bits saved with save().
 
 BitArray (std::ifstream &input)
 Build a new array of bits from a file constructed using the save() method.
 
void save_in_array_of_chars (const std::string &name, std::ostream &output) const
 Saves a static string declaration to a text file.
 
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.
 
void left_shift (const size_t n=1)
 Shifts the bits n positions to the left.
 
void right_shift (const size_t n=1)
 Shifts the bits n positions to the right.
 
void dyn_left_shift (const size_t n=1)
 Shifts bits n positions to the left dynamically.
 
void dyn_right_shift (const size_t n=1)
 Shifts bits n positions to the right dynamically.
 
void circular_left_shift (const size_t n=1)
 Shifts the bits n positions to the left circularly.
 
void circular_right_shift (const size_t n=1)
 Shifts the bits n positions to the right circularly.
 
template<typename T >
void set_num (T n)
 
void set_num (const char &c)
 
void set_num (const short &c)
 
void set_num (const int &c)
 
void set_num (const long &c)
 
unsigned long get_unum () const noexcept
 
long get_num () const noexcept
 
void set_bit_str (const std::string &str)
 
std::string get_bit_str () const
 
std::string to_string () const
 
 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_of_chars.
 
BitArray & operator|= (const BitArray &rhs)
 
BitArray & operator&= (const BitArray &rhs)
 
bool operator== (const BitArray &rhs) const
 
auto get_it () const noexcept
 
template<class Operation >
bool traverse (Operation &operation) const
 
template<class Operation >
bool traverse (Operation &operation)
 
template<class Operation >
bool traverse (Operation &&operation=Operation()) const
 
template<class Operation >
bool traverse (Operation &&operation=Operation())
 
template<template< typename > class Container = DynList>
Container< unsigned int > items () const
 
iterator begin () noexcept
 
iterator end () noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
const_iterator cbegin () noexcept
 
const_iterator cend () noexcept
 
int count_ones () const noexcept
 
int count_zeros () const noexcept
 
- Public Member Functions inherited from Aleph::FunctionalMixin< BitArray, unsigned int >
auto for_each (Operation &operation) const -> decltype(self())
 Apply an operation to each element (read-only).
 
auto for_each (Operation &operation) -> decltype(self())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
auto for_each (Operation &&operation=Operation()) const -> decltype(self())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
auto for_each (Operation &&operation=Operation()) -> decltype(self())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
auto mutable_for_each (Operation &operation) -> decltype(self())
 Apply an operation to each element (mutable).
 
auto mutable_for_each (Operation &&operation=Operation()) -> decltype(self())
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool all (Operation &operation) const
 Test if all elements satisfy a predicate.
 
bool all (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool forall (Operation &operation) const
 Alias for all().
 
bool forall (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
bool exists (Operation &operation) const
 Test if any element satisfies a predicate.
 
bool exists (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
Container< concepts_detail::map_result_t< R, Operation &, unsigned int > > maps (Operation &operation) const
 
Container< concepts_detail::map_result_t< R, Operation &, unsigned int > > maps (Operation &&operation=Operation()) const
 
Acc foldl (const Acc &init, std::function< Acc(const Acc &, const unsigned int &)> operation) const
 Left fold (reduce) with initial value.
 
Acc fold_left (std::function< Acc(const Acc &, const unsigned int &)> operation, const Acc &init) const
 Left fold with operation first (alternative signature).
 
unsigned int fold (const unsigned int &init, Operation &operation) const
 Simple fold with same type for accumulator and elements.
 
unsigned int fold (const unsigned int &init, Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
DynList< unsigned int > filter (Operation &operation) const
 Filter elements by a predicate.
 
DynList< unsigned int > filter (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
DynList< std::tuple< unsigned int, size_t > > pfilter (Operation &operation) const
 Filter with position information.
 
DynList< std::tuple< unsigned int, size_t > > pfilter (Operation &&operation=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
std::pair< DynList< unsigned int >, DynList< unsigned int > > partition (Operation &op) const
 Partition elements by a predicate.
 
std::pair< DynList< unsigned int >, DynList< unsigned int > > partition (Operation &&op=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
std::tuple< DynList< unsigned int >, DynList< unsigned int > > tpartition (Operation &op) const
 Partition returning tuple instead of pair.
 
std::tuple< DynList< unsigned int >, DynList< unsigned int > > tpartition (Operation &&op=Operation()) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
size_t length () const noexcept
 Count the number of elements.
 
Container< unsigned int > rev () const
 Create a reversed copy.
 
Container< unsigned int > take (const size_t n) const
 Take the first n elements.
 
Container< unsigned int > drop (const size_t n) const
 Skip the first n elements.
 
unsigned int sum (const unsigned int &init=unsigned int {}) const
 Compute the sum of all elements.
 
unsigned int product (const unsigned int &init) const
 Compute the product of all elements.
 
const unsigned int * min () const
 Find the minimum element.
 
const unsigned int * max () const
 Find the maximum element.
 
const unsigned int * min_by (Compare cmp) const
 Find the minimum element using a custom comparator.
 
const unsigned int * max_by (Compare cmp) const
 Find the maximum element using a custom comparator.
 
bool has_value (const unsigned int &val) const
 Check if container has a value.
 
bool none (Predicate &pred) const
 Check if no element satisfies a predicate.
 
bool none (Predicate &&pred) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
 
size_t count_if (Predicate pred) const
 Count elements satisfying a predicate.
 
const unsigned int * first () const
 Get the first element.
 
unsigned int first_or (const unsigned int &default_val) const
 Get the first element or a default value.
 
const unsigned int * last () const
 Get the last element.
 
unsigned int last_or (const unsigned int &default_val) const
 Get the last element or a default value.
 
Container< std::pair< size_t, unsigned int > > enumerate () const
 Enumerate elements with their indices.
 
size_t find_index (Predicate pred) const
 Find the index of the first element satisfying a predicate.
 
size_t index_of (const unsigned int &val) const
 Find the index of a specific value.
 
Container< unsigned int > unique () const
 Remove consecutive duplicate elements.
 
Container< unsigned int > unique_by (EqPred eq) const
 Remove consecutive duplicates using a custom equality predicate.
 
Container< unsigned int > intersperse (const unsigned int &sep) const
 Intersperse a separator between elements.
 
Container< Container< unsigned int > > chunk (size_t n) const
 Split into chunks of fixed size.
 
Container< Container< unsigned int > > sliding (size_t size, size_t step=1) const
 Create sliding windows of fixed size.
 
std::vector< unsigned int > to_vector () const
 Convert to std::vector.
 
DynListType to_dynlist () const
 Convert container to DynList.
 
StringType join (const StringType &sep=StringType{", "}) const
 Join elements into a string with separator.
 
std::string join_str (const std::string &sep=", ") const
 Join string elements with separator.
 
Container< std::pair< unsigned int, typename Other::Item_Type > > zip_with (const Other &other) const
 Zip with another container.
 

Private Member Functions

void clear_unused_bits_in_last_byte () noexcept
 
void ensure_num_bytes (const size_t num_bytes)
 
size_t get_num_bytes () const noexcept
 
template<class Operation >
bool __traverse (Operation &operation)
 

Private Attributes

size_t current_size
 
DynArray< Byte > array_of_bytes
 

Friends

std::ostream & operator<< (std::ostream &out, const BitArray &array)
 
BitArray operator| (const BitArray &op1, const BitArray &op2)
 
BitArray operator& (const BitArray &op1, const BitArray &op2)
 
const_iterator cbegin (const BitArray &s) noexcept
 
const_iterator cend (const BitArray &s) noexcept
 
const_iterator begin (const BitArray &s) noexcept
 
const_iterator end (const BitArray &s) noexcept
 
iterator begin (BitArray &s) noexcept
 
iterator end (BitArray &s) noexcept
 

Additional Inherited Members

- Public Attributes inherited from Aleph::FunctionalMixin< BitArray, unsigned int >
 and
 Transform elements using a mapping function.
 
- Protected Member Functions inherited from Aleph::FunctionalMixin< BitArray, unsigned int >
const BitArray & self () const noexcept
 
BitArray & self () noexcept
 

Detailed Description

Contiguous array of bits.

BitArray defines a contiguous array of bits. The consumption of memory is proportional to n/8; where n is the number of bits that you want to manage.

The array is dynamic, which means it can expand dynamically according to need.

Access to the ith bit can be done using the operator []. However, since this kind of access is implemented using a proxy class, access may fail in some expressions where the compiler cannot carry out the appropriate type transformations.

Author
Alejandro Mujica
Leandro Rabindranath Leon

Definition at line 200 of file bitArray.H.

Member Typedef Documentation

◆ const_iterator

◆ Item_Type

using Aleph::BitArray::Item_Type = unsigned int

Type returned by Iterator::get_curr() - individual bits as unsigned int.

Definition at line 307 of file bitArray.H.

◆ iterator

Definition at line 1210 of file bitArray.H.

Constructor & Destructor Documentation

◆ BitArray() [1/6]

Aleph::BitArray::BitArray ( const size_t  dim = 0)
inline

Bit array constructor.

Parameters
[in]dimnumber of bits. By default, it is 256.
Exceptions
bad_allocif there is not enough memory for a block continuous dim/8 bytes.

Definition at line 315 of file bitArray.H.

References array_of_bytes.

◆ BitArray() [2/6]

Aleph::BitArray::BitArray ( const size_t  dim,
const unsigned int  value 
)
inline

Build a BitArray of size dim with all bits set to value.

Definition at line 322 of file bitArray.H.

References dim(), value, and write_bit().

◆ BitArray() [3/6]

Aleph::BitArray::BitArray ( const BitArray &  array)
inline

Copy constructor.

Instantiates an array of bits exact copy of array.

Parameters
[in]arraythe array of bits to be copied.
Exceptions
bad_allocif there is not enough memory for a block continuous dim/8 bytes.

Definition at line 535 of file bitArray.H.

◆ BitArray() [4/6]

Aleph::BitArray::BitArray ( BitArray &&  array)
inlinenoexcept

Move constructor; it allocates nothing.

It takes the bytes of array. It does not build an empty array first, which allocates a directory: without memory for it, a constructor that is noexcept would end the program.

Parameters
[in,out]arraythe source, left empty and reusable.

Definition at line 555 of file bitArray.H.

◆ BitArray() [5/6]

Aleph::BitArray::BitArray ( std::ifstream &  input)
inline

Build a new array of bits from a file constructed using the save() method.

Definition at line 698 of file bitArray.H.

References load().

◆ BitArray() [6/6]

Aleph::BitArray::BitArray ( const unsigned char  str[],
const size_t  num_bits 
)
inline

Constructs a new array of bits from an array of characters previously generated with load_from_array_of_chars.

Definition at line 1004 of file bitArray.H.

References load_from_array_of_chars().

Member Function Documentation

◆ __traverse()

template<class Operation >
bool Aleph::BitArray::__traverse ( Operation &  operation)
inlineprivate

Definition at line 1095 of file bitArray.H.

References current_size, and read_bit().

Referenced by traverse(), and traverse().

◆ begin() [1/2]

const_iterator Aleph::BitArray::begin ( ) const
inlinenoexcept

Definition at line 1210 of file bitArray.H.

◆ begin() [2/2]

iterator Aleph::BitArray::begin ( )
inlinenoexcept

Definition at line 1210 of file bitArray.H.

◆ bits_list()

DynList< char > Aleph::BitArray::bits_list ( ) const
inline

Converts it to a list.

Definition at line 570 of file bitArray.H.

References Aleph::DynList< T >::append(), current_size, and read_bit().

◆ cbegin() [1/2]

const_iterator Aleph::BitArray::cbegin ( ) const
inlinenoexcept

Definition at line 1210 of file bitArray.H.

◆ cbegin() [2/2]

const_iterator Aleph::BitArray::cbegin ( )
inlinenoexcept

Definition at line 1210 of file bitArray.H.

◆ cend() [1/2]

const_iterator Aleph::BitArray::cend ( ) const
inlinenoexcept

Definition at line 1210 of file bitArray.H.

◆ cend() [2/2]

const_iterator Aleph::BitArray::cend ( )
inlinenoexcept

Definition at line 1210 of file bitArray.H.

◆ circular_left_shift()

void Aleph::BitArray::circular_left_shift ( const size_t  n = 1)
inline

Shifts the bits n positions to the left circularly.

The bits are shifted without losing any, the first n bits They begin to occupy the last n positions in the arrangement.

Parameters
[in]nthe number of positions to shift the bits.

Definition at line 863 of file bitArray.H.

References current_size, read_bit(), and write_bit().

◆ circular_right_shift()

void Aleph::BitArray::circular_right_shift ( const size_t  n = 1)
inline

Shifts the bits n positions to the right circularly.

The bits are shifted without losing any, the last n bits They come to occupy the first n positions in the arrangement.

Parameters
[in]nthe number of positions to shift the bits.

Definition at line 892 of file bitArray.H.

References current_size, read_bit(), and write_bit().

◆ clear_unused_bits_in_last_byte()

◆ count_ones()

int Aleph::BitArray::count_ones ( ) const
inlinenoexcept

Definition at line 1212 of file bitArray.H.

◆ count_zeros()

int Aleph::BitArray::count_zeros ( ) const
inlinenoexcept

Definition at line 1217 of file bitArray.H.

◆ dyn_left_shift()

void Aleph::BitArray::dyn_left_shift ( const size_t  n = 1)
inline

Shifts bits n positions to the left dynamically.

The bits are shifted without losing any and the array grows adding n zeros to the right.

Parameters
[in]nthe number of positions to shift the bits.

Definition at line 822 of file bitArray.H.

References push().

◆ dyn_right_shift()

void Aleph::BitArray::dyn_right_shift ( const size_t  n = 1)
inline

Shifts bits n positions to the right dynamically.

The bits are shifted without losing any and the array is decremented. eliminating the n zeros that would be on the left

Parameters
[in]nthe number of positions to shift the bits.

Definition at line 835 of file bitArray.H.

References clear_unused_bits_in_last_byte(), current_size, read_bit(), set_size(), and write_bit().

◆ empty()

void Aleph::BitArray::empty ( )
inlinenoexcept

Delete all inserted bits.

Definition at line 521 of file bitArray.H.

References array_of_bytes, and current_size.

Referenced by set_bit_str(), and set_num().

◆ end() [1/2]

const_iterator Aleph::BitArray::end ( ) const
inlinenoexcept

Definition at line 1210 of file bitArray.H.

◆ end() [2/2]

iterator Aleph::BitArray::end ( )
inlinenoexcept

Definition at line 1210 of file bitArray.H.

◆ ensure_num_bytes()

void Aleph::BitArray::ensure_num_bytes ( const size_t  num_bytes)
inlineprivate

Definition at line 223 of file bitArray.H.

References array_of_bytes.

Referenced by operator|=().

◆ fast_read()

int Aleph::BitArray::fast_read ( const size_t  i) const
inlinenoexcept

Read bit i without any check.

Parameters
[in]iindex of the bit.
Returns
the value of bit i
Precondition
i < size(), which debug builds assert, and the memory of bit i exists: reserve() or set_size() covered it, or it was written before.

Definition at line 482 of file bitArray.H.

References array_of_bytes, and current_size.

Referenced by Aleph::Bloom_Filter< T >::contains(), Aleph::Compact_Quotient_Filter< T >::get_bit_at(), Aleph::Compact_Quotient_Filter< T >::get_rem(), and Aleph::Compact_Quotient_Filter< T >::slot_empty().

◆ fast_write()

void Aleph::BitArray::fast_write ( const size_t  i,
const unsigned int  value 
)
inline

Write bit i without checking i.

It does not change size().

Parameters
[in]iindex of the bit.
[in]value0 or 1.
Exceptions
out_of_rangeif value is neither 0 nor 1.
Precondition
i < size(), which debug builds assert, and the memory of bit i exists: reserve() or set_size() covered it, or it was written before. A bit past size() would come back when the size grows, where reserve() and set_size() give new bits of 0.

Definition at line 498 of file bitArray.H.

References ah_out_of_range_error_if, array_of_bytes, current_size, and value.

Referenced by Aleph::Compact_Quotient_Filter< T >::clear(), Aleph::Bloom_Filter< T >::insert(), Aleph::Compact_Quotient_Filter< T >::set_bit_at(), and Aleph::Compact_Quotient_Filter< T >::set_rem().

◆ get_bit_str()

std::string Aleph::BitArray::get_bit_str ( ) const
inline

Definition at line 981 of file bitArray.H.

References current_size, and read_bit().

Referenced by TEST(), to_string(), and Moved_From_Case< BitArray >::use().

◆ get_it()

auto Aleph::BitArray::get_it ( ) const
inlinenoexcept

Definition at line 1180 of file bitArray.H.

◆ get_num()

long Aleph::BitArray::get_num ( ) const
inlinenoexcept

Definition at line 961 of file bitArray.H.

References get_unum().

◆ get_num_bytes()

size_t Aleph::BitArray::get_num_bytes ( ) const
inlineprivatenoexcept

Definition at line 235 of file bitArray.H.

References current_size.

Referenced by operator&=(), operator|=(), pop(), save(), and save_in_array_of_chars().

◆ get_unum()

unsigned long Aleph::BitArray::get_unum ( ) const
inlinenoexcept

Definition at line 949 of file bitArray.H.

References current_size, and read_bit_ne().

Referenced by get_num().

◆ items()

template<template< typename > class Container = DynList>
Container< unsigned int > Aleph::BitArray::items ( ) const
inline

Definition at line 1208 of file bitArray.H.

◆ left_shift()

void Aleph::BitArray::left_shift ( const size_t  n = 1)
inline

Shifts the bits n positions to the left.

The bits are shifted and the array is considered a fixed size, that is, the first n bits are lost.

Parameters
[in]nthe number of positions to shift the bits.

Definition at line 786 of file bitArray.H.

References current_size, read_bit(), and write_bit().

◆ load()

void Aleph::BitArray::load ( std::istream &  input)
inline

Loads an array of bits saved with save().

load(input) reads the header that save() writes, the number of bytes and the number of bits, then the bytes, and restores the array to the value saved. The header is checked before anything is reserved: its two numbers must agree, and the bytes cannot be more than a DynArray holds (DynArray::Max_Dim_Allowed). Each byte is stored as it is read, so a header that claims more bytes than the input has takes no more memory than the bytes read.

Parameters
[in]inputstream with an array of bits saved with save().
Exceptions
std::runtime_errorif the header or a byte cannot be read, if the header is inconsistent or claims too many bytes, or if a byte is not in [0, 255]. Then this is as it was.
std::bad_allocif there is not enough memory. Then this is as it was.

Definition at line 661 of file bitArray.H.

References ah_runtime_error_if, array_of_bytes, clear_unused_bits_in_last_byte(), current_size, and swap().

Referenced by BitArray(), Aleph::Huffman_Encoder_Engine::load_tree(), Aleph::load_tree(), and main().

◆ load_from_array_of_chars()

void Aleph::BitArray::load_from_array_of_chars ( const unsigned char  str[],
const size_t  num_bits 
)
inline

Reads an array of bits saved in a character array.

load_from_array_of_chars(str, num_bits) takes an array str, previously generated with save_in_array_of_chars, of num_bits long, and loads it.

Parameters
[in]strthe character array where the of is located bits.
[in]num_bitsthe number of bits in the array. Note that not is the same as the number of bytes.

Definition at line 762 of file bitArray.H.

References array_of_bytes, clear_unused_bits_in_last_byte(), and current_size.

Referenced by BitArray(), and Aleph::load_tree_from_array().

◆ operator&=()

BitArray & Aleph::BitArray::operator&= ( const BitArray &  rhs)
inline

◆ operator()()

int Aleph::BitArray::operator() ( const size_t  i) const
inline

Definition at line 415 of file bitArray.H.

References read_bit().

◆ operator=() [1/2]

BitArray & Aleph::BitArray::operator= ( BitArray &&  array)
inlinenoexcept

Definition at line 561 of file bitArray.H.

References array_of_bytes, current_size, and swap().

◆ operator=() [2/2]

BitArray & Aleph::BitArray::operator= ( const BitArray &  array)
inline

Bit array allocation.

Release all memory of this, set aside new memory for host array and exactly copies the bits of array to this.

Parameters
[in]arraythe array of bits to be copied.
Exceptions
bad_allocif there is not enough memory for a block continuous dim/8 bytes.
Note
If this exception occurs, the state of this remains the same prior to assignment.

Definition at line 589 of file bitArray.H.

References array_of_bytes, and current_size.

◆ operator==()

bool Aleph::BitArray::operator== ( const BitArray &  rhs) const
inline

Definition at line 1081 of file bitArray.H.

References read_bit(), and size().

◆ operator[]() [1/2]

int Aleph::BitArray::operator[] ( const size_t  i) const
inline

Definition at line 388 of file bitArray.H.

References read_bit().

◆ operator[]() [2/2]

BitProxy Aleph::BitArray::operator[] ( const size_t  i)
inlinenoexcept

Definition at line 390 of file bitArray.H.

◆ operator|=()

BitArray & Aleph::BitArray::operator|= ( const BitArray &  rhs)
inline

◆ pop()

void Aleph::BitArray::pop ( )
inline

◆ push()

void Aleph::BitArray::push ( const unsigned int  value)
inline

◆ read()

int Aleph::BitArray::read ( const size_t  i) const
inline

Quick read of bit i.

Read bit i without checking memory

Parameters
[in]iindex of the bit to be read.
Returns
the value of bit i
Note
No checking out of range.
Precondition
The memory of bit i exists: reserve() or set_size() covered it, or it was written before.

Definition at line 445 of file bitArray.H.

References ah_out_of_range_error_if, array_of_bytes, and current_size.

◆ read_bit()

◆ read_bit_ne()

int Aleph::BitArray::read_bit_ne ( const size_t  i) const
inlinenoexcept

Definition at line 392 of file bitArray.H.

References array_of_bytes, and Aleph::Byte::read_bit().

Referenced by Aleph::BitArray::Iterator::get_curr_ne(), get_unum(), and read_bit().

◆ reserve()

void Aleph::BitArray::reserve ( const size_t  dim)
inline

Reserve memory in advance for the bit array dim dimension.

reserve() sets aside the memory of dim bits and sets size() to dim, as set_size() does: a smaller dim drops the last bits, and the new bits are 0. After it, the bits below dim can be accessed with read(), write(), fast_read() and fast_write(), which are faster because they do not allocate memory.

Exceptions
bad_allocif not enough memory
length_errorif dim bits need more bytes than a DynArray holds (DynArray::Max_Dim_Allowed).
Note
If it throws, the array is as it was.

Definition at line 344 of file bitArray.H.

References dim(), and set_size().

Referenced by Aleph::Bloom_Filter< T >::Bloom_Filter(), Aleph::Compact_Quotient_Filter< T >::Compact_Quotient_Filter(), set_bit_str(), set_num(), and TEST().

◆ right_shift()

void Aleph::BitArray::right_shift ( const size_t  n = 1)
inline

Shifts the bits n positions to the right.

The bits are shifted and the array is considered a fixed size, that is, the last n bits are lost.

Parameters
[in]nthe number of positions to shift the bits.

Definition at line 804 of file bitArray.H.

References current_size, read_bit(), and write_bit().

◆ save()

void Aleph::BitArray::save ( std::ostream &  output) const
inline

Saves the bit sequence in a text file.

save() stores the sequence in the output text file, already opened, of bits in decimal format.

The first line always saves the size in bytes and in bits. The sequential bytes are then saved as a decimal value. corresponding to the arrangement.

Parameters
[in]outputopen output stream where the arrangement.

Definition at line 612 of file bitArray.H.

References ah_runtime_error_if, array_of_bytes, current_size, get_num_bytes(), and output.

Referenced by main().

◆ save_in_array_of_chars()

void Aleph::BitArray::save_in_array_of_chars ( const std::string &  name,
std::ostream &  output 
) const
inline

Saves a static string declaration to a text file.

characters representing the arrangement.

save_in_array_of_chars(name, output) generates a declaration of the guy:

char name [ size ] = { comma-separated array values };

The declaration is saved in the output stream and the array name is name.

Parameters
[in]namename of the array variable.
[in]outputoutput stream where you want to save the statement.

Definition at line 718 of file bitArray.H.

References array_of_bytes, current_size, get_num_bytes(), and output.

◆ set_bit_str()

void Aleph::BitArray::set_bit_str ( const std::string &  str)
inline

Definition at line 966 of file bitArray.H.

References empty(), reserve(), and write_bit().

Referenced by TEST().

◆ set_num() [1/5]

void Aleph::BitArray::set_num ( const char &  c)
inline

Definition at line 929 of file bitArray.H.

◆ set_num() [2/5]

void Aleph::BitArray::set_num ( const int &  c)
inline

Definition at line 939 of file bitArray.H.

◆ set_num() [3/5]

void Aleph::BitArray::set_num ( const long &  c)
inline

Definition at line 944 of file bitArray.H.

◆ set_num() [4/5]

void Aleph::BitArray::set_num ( const short &  c)
inline

Definition at line 934 of file bitArray.H.

◆ set_num() [5/5]

template<typename T >
void Aleph::BitArray::set_num ( T  n)
inline

Definition at line 915 of file bitArray.H.

References current_size, empty(), reserve(), and write_bit().

◆ set_size()

void Aleph::BitArray::set_size ( const size_t  sz)
inline

Resets the dimension of the array.

It allocates the memory of all the sz bits, as reserve() says.

Parameters
[in]szthe new number of bits
Exceptions
bad_allocif not enough memory
length_errorif sz bits need more bytes than a DynArray holds (DynArray::Max_Dim_Allowed).
Note
If it throws, the array is as it was.

Definition at line 362 of file bitArray.H.

References array_of_bytes, clear_unused_bits_in_last_byte(), current_size, and write_bit().

Referenced by dyn_right_shift(), reserve(), and TEST().

◆ size()

◆ swap()

void Aleph::BitArray::swap ( BitArray &  array)
inlinenoexcept

◆ to_string()

std::string Aleph::BitArray::to_string ( ) const
inline

Definition at line 990 of file bitArray.H.

References get_bit_str().

◆ traverse() [1/4]

template<class Operation >
bool Aleph::BitArray::traverse ( Operation &&  operation = Operation())
inline

Definition at line 1201 of file bitArray.H.

◆ traverse() [2/4]

template<class Operation >
bool Aleph::BitArray::traverse ( Operation &&  operation = Operation()) const
inline

Definition at line 1195 of file bitArray.H.

◆ traverse() [3/4]

template<class Operation >
bool Aleph::BitArray::traverse ( Operation &  operation)
inline

Definition at line 1189 of file bitArray.H.

References __traverse().

◆ traverse() [4/4]

template<class Operation >
bool Aleph::BitArray::traverse ( Operation &  operation) const
inline

Definition at line 1183 of file bitArray.H.

References __traverse().

◆ write()

void Aleph::BitArray::write ( const size_t  i,
const unsigned int  value 
)
inline

Writes bit i with value without memory check.

Parameters
[in]iindex of the bit to be written.
[in]valuevalue to be written at position i.
Note
It doesn't check out of range, and it doesn't check that value have a binary value.
Precondition
The memory of bit i exists: reserve() or set_size() covered it, or it was written before.

Definition at line 462 of file bitArray.H.

References ah_out_of_range_error_if, array_of_bytes, clear_unused_bits_in_last_byte(), current_size, and value.

◆ write_bit()

Friends And Related Symbol Documentation

◆ begin [1/2]

iterator begin ( BitArray &  s)
friend

Definition at line 1210 of file bitArray.H.

◆ begin [2/2]

const_iterator begin ( const BitArray &  s)
friend

Definition at line 1210 of file bitArray.H.

◆ cbegin

const_iterator cbegin ( const BitArray &  s)
friend

Definition at line 1210 of file bitArray.H.

◆ cend

const_iterator cend ( const BitArray &  s)
friend

Definition at line 1210 of file bitArray.H.

◆ end [1/2]

iterator end ( BitArray &  s)
friend

Definition at line 1210 of file bitArray.H.

◆ end [2/2]

const_iterator end ( const BitArray &  s)
friend

Definition at line 1210 of file bitArray.H.

◆ operator&

BitArray operator& ( const BitArray &  op1,
const BitArray &  op2 
)
friend

Definition at line 1074 of file bitArray.H.

◆ operator<<

std::ostream & operator<< ( std::ostream &  out,
const BitArray &  array 
)
friend

Definition at line 995 of file bitArray.H.

◆ operator|

BitArray operator| ( const BitArray &  op1,
const BitArray &  op2 
)
friend

Definition at line 1067 of file bitArray.H.

Member Data Documentation

◆ array_of_bytes

◆ current_size


The documentation for this class was generated from the following file: