5#ifndef BITCOIN_UTIL_BITDEQUE_H
6#define BITCOIN_UTIL_BITDEQUE_H
22template <
int BlobSize = 4096 * 8>
class bitdeque {
30 template <
bool Const>
class Iterator;
36 std::conditional_t<Const,
typename deque_type::const_iterator,
37 typename deque_type::iterator>;
51 std::conditional_t<Const, bool, typename word_type::reference>;
63 typename = std::enable_if_t<Const && ConstArg>>
77 }
else if (
dist < 0) {
155 return *(*
this + pos);
337 std::numeric_limits<difference_type>::max() /
BITS_PER_WORD) {
340 return std::numeric_limits<difference_type>::max();
349 while (first != last) {
350 *(it++) = *(first++);
379 throw std::out_of_range(
"bitdeque::at() out of range");
384 throw std::out_of_range(
"bitdeque::at() out of range");
448 std::swap(
m_deque, other.m_deque);
500 template <
typename It>
507 while (first != last) {
508 *(it++) = *(first++);
Iterator to a bitdeque element, const or not.
friend bool operator!=(const Iterator &x, const Iterator &y)
Iterator(const deque_iterator &it, int bitpos)
Iterator & operator+=(difference_type dist)
friend bool operator==(const Iterator &x, const Iterator &y)
reference operator*() const
Iterator(const Iterator< false > &x)
Conversion from non-const to const iterator.
Iterator & operator-=(difference_type dist)
Iterator()=default
Default constructor.
std::random_access_iterator_tag iterator_category
Iterator & operator=(const Iterator &)=default
friend Iterator operator-(Iterator x, difference_type dist)
friend Iterator operator+(Iterator x, difference_type dist)
Iterator(const Iterator &)=default
Default copy constructor.
std::conditional_t< Const, bool, typename word_type::reference > reference
friend bool operator>=(const Iterator &x, const Iterator &y)
friend difference_type operator-(const Iterator &x, const Iterator &y)
std::ptrdiff_t difference_type
std::conditional_t< Const, typename deque_type::const_iterator, typename deque_type::iterator > deque_iterator
friend bool operator>(const Iterator &x, const Iterator &y)
reference operator[](difference_type pos) const
friend bool operator<=(const Iterator &x, const Iterator &y)
friend Iterator operator+(difference_type dist, Iterator x)
friend bool operator<(const Iterator &x, const Iterator &y)
Class that mimics std::deque<bool>, but with std::vector<bool>'s bit packing.
bitdeque & operator=(std::initializer_list< bool > ilist)
Set the container equal to the bits in ilist.
iterator erase(iterator first, iterator last)
const_reference operator[](size_type position) const
bitdeque(size_t count)
Construct a container containing count false values.
iterator insert(const_iterator pos, bool val)
void push_front(bool val)
typename deque_type::difference_type difference_type
const_reverse_iterator crend() const noexcept
void assign(It first, It last)
Set the container equal to the bits in [first,last).
std::deque< word_type > deque_type
iterator erase(iterator pos)
iterator begin() noexcept
void erase_front(size_type n)
Shrink the container by n bits, removing from the beginning.
bitdeque(const bitdeque &)=default
Copy constructor.
const_reverse_iterator rbegin() const noexcept
iterator emplace(const_iterator pos, bool val)
int m_pad_end
Number of unused bits at the back of m_deque.back().
iterator insert(const_iterator pos, It first, It last)
const_reference front() const
const_iterator end() const noexcept
bitdeque(std::initializer_list< bool > ilist)
Construct a container containing the bits in ilist.
friend void swap(bitdeque &b1, bitdeque &b2) noexcept
iterator erase(const_iterator first, const_iterator last)
deque_type m_deque
Deque of bitsets storing the actual bit data.
const_iterator cend() const noexcept
std::bitset< BlobSize > word_type
reverse_iterator rend() noexcept
std::reverse_iterator< const_iterator > const_reverse_iterator
bitdeque(bitdeque &&) noexcept=default
Move constructor.
const_reverse_iterator rend() const noexcept
reference emplace_front(bool val)
const_reverse_iterator crbegin() const noexcept
void assign(size_type count, bool val)
Set the container equal to count times the value of val.
reference emplace_back(bool val)
bitdeque(size_type count, bool val)
Construct a container containing count times the value of val.
size_type max_size() const noexcept
Return the maximum size of the container.
const_reference back() const
bitdeque(It first, It last)
Construct a container containing the bits in [first,last).
size_type size() const noexcept
Count the number of bits in the container.
void resize(size_type n)
Resize the container.
int m_pad_begin
Number of unused bits at the front of m_deque.front().
typename word_type::reference reference
bool empty() const noexcept
Determine whether the container is empty.
iterator erase(const_iterator pos)
void extend_front(size_type n)
Extend the container by n bits, adding at the beginning.
void insert_zeroes(size_type before, size_type count)
Insert a sequence of falses anywhere in the container.
iterator insert(const_iterator pos, size_type count, bool val)
const_iterator cbegin() const noexcept
std::reverse_iterator< iterator > reverse_iterator
const_iterator begin() const noexcept
static constexpr int BITS_PER_WORD
reference operator[](size_type position)
reference at(size_type position)
void swap(bitdeque &other) noexcept
const_reference at(size_type position) const
void assign(std::initializer_list< bool > ilist)
Set the container equal to the bits in ilist.
void extend_back(size_type n)
Extend the container by n bits, adding at the end.
void clear() noexcept
Empty the container.
void erase_back(size_type n)
Shrink the container by n bits, removing from the end.
bitdeque()
Construct an empty container.
reverse_iterator rbegin() noexcept
void shrink_to_fit()
Release unused memory.
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...