Bitcoin Core 31.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
bitdeque< BITS_PER_WORD > Class Template Reference

Class that mimics std::deque<bool>, but with std::vector<bool>'s bit packing. More...

#include <bitdeque.h>

Classes

class  Iterator
 Iterator to a bitdeque element, const or not. More...

Public Types

using value_type = bool
using size_type = std::size_t
using difference_type = typename deque_type::difference_type
using reference = typename word_type::reference
using const_reference = bool
using iterator = Iterator<false>
using const_iterator = Iterator<true>
using pointer = void
using const_pointer = void
using reverse_iterator = std::reverse_iterator<iterator>
using const_reverse_iterator = std::reverse_iterator<const_iterator>

Public Member Functions

 bitdeque ()
 Construct an empty container.
void assign (size_type count, bool val)
 Set the container equal to count times the value of val.
 bitdeque (size_type count, bool val)
 Construct a container containing count times the value of val.
 bitdeque (size_t count)
 Construct a container containing count false values.
 bitdeque (const bitdeque &)=default
 Copy constructor.
 bitdeque (bitdeque &&) noexcept=default
 Move constructor.
bitdequeoperator= (const bitdeque &other)=default
 Copy assignment operator.
bitdequeoperator= (bitdeque &&other) noexcept=default
 Move assignment operator.
iterator begin () noexcept
iterator end () noexcept
const_iterator begin () const noexcept
const_iterator cbegin () const noexcept
const_iterator end () const noexcept
const_iterator cend () const noexcept
reverse_iterator rbegin () noexcept
reverse_iterator rend () noexcept
const_reverse_iterator rbegin () const noexcept
const_reverse_iterator crbegin () const noexcept
const_reverse_iterator rend () const noexcept
const_reverse_iterator crend () const noexcept
size_type size () const noexcept
 Count the number of bits in the container.
bool empty () const noexcept
 Determine whether the container is empty.
size_type max_size () const noexcept
 Return the maximum size of the container.
template<typename It>
void assign (It first, It last)
 Set the container equal to the bits in [first,last).
void assign (std::initializer_list< bool > ilist)
 Set the container equal to the bits in ilist.
bitdequeoperator= (std::initializer_list< bool > ilist)
 Set the container equal to the bits in ilist.
template<typename It>
 bitdeque (It first, It last)
 Construct a container containing the bits in [first,last).
 bitdeque (std::initializer_list< bool > ilist)
 Construct a container containing the bits in ilist.
reference at (size_type position)
const_reference at (size_type position) const
reference operator[] (size_type position)
const_reference operator[] (size_type position) const
reference front ()
const_reference front () const
reference back ()
const_reference back () const
void shrink_to_fit ()
 Release unused memory.
void clear () noexcept
 Empty the container.
void push_back (bool val)
reference emplace_back (bool val)
void push_front (bool val)
reference emplace_front (bool val)
void pop_back ()
void pop_front ()
void resize (size_type n)
 Resize the container.
void swap (bitdeque &other) noexcept
iterator erase (const_iterator first, const_iterator last)
iterator erase (iterator first, iterator last)
iterator erase (const_iterator pos)
iterator erase (iterator pos)
iterator insert (const_iterator pos, bool val)
iterator emplace (const_iterator pos, bool val)
iterator insert (const_iterator pos, size_type count, bool val)
template<typename It>
iterator insert (const_iterator pos, It first, It last)

Private Types

using word_type = std::bitset<BITS_PER_WORD>
using deque_type = std::deque<word_type>

Private Member Functions

void erase_back (size_type n)
 Shrink the container by n bits, removing from the end.
void extend_back (size_type n)
 Extend the container by n bits, adding at the end.
void erase_front (size_type n)
 Shrink the container by n bits, removing from the beginning.
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.

Private Attributes

deque_type m_deque
 Deque of bitsets storing the actual bit data.
int m_pad_begin
 Number of unused bits at the front of m_deque.front().
int m_pad_end
 Number of unused bits at the back of m_deque.back().

Friends

template<bool Const>
class Iterator
void swap (bitdeque &b1, bitdeque &b2) noexcept

Detailed Description

template<int BITS_PER_WORD = 4096 * 8>
class bitdeque< BITS_PER_WORD >

Class that mimics std::deque<bool>, but with std::vector<bool>'s bit packing.

BITS_PER_WORD selects the (minimum) number of bits that are allocated at once. Larger values reduce the asymptotic memory usage overhead, at the cost of needing larger up-front allocations. The default is 4096 bytes.

Definition at line 22 of file bitdeque.h.

Member Typedef Documentation

◆ const_iterator

template<int BITS_PER_WORD = 4096 * 8>
using bitdeque< BITS_PER_WORD >::const_iterator = Iterator<true>

Definition at line 115 of file bitdeque.h.

◆ const_pointer

template<int BITS_PER_WORD = 4096 * 8>
using bitdeque< BITS_PER_WORD >::const_pointer = void

Definition at line 117 of file bitdeque.h.

◆ const_reference

template<int BITS_PER_WORD = 4096 * 8>
using bitdeque< BITS_PER_WORD >::const_reference = bool

Definition at line 113 of file bitdeque.h.

◆ const_reverse_iterator

template<int BITS_PER_WORD = 4096 * 8>
using bitdeque< BITS_PER_WORD >::const_reverse_iterator = std::reverse_iterator<const_iterator>

Definition at line 119 of file bitdeque.h.

◆ deque_type

template<int BITS_PER_WORD = 4096 * 8>
using bitdeque< BITS_PER_WORD >::deque_type = std::deque<word_type>
private

Definition at line 26 of file bitdeque.h.

◆ difference_type

template<int BITS_PER_WORD = 4096 * 8>
using bitdeque< BITS_PER_WORD >::difference_type = typename deque_type::difference_type

Definition at line 111 of file bitdeque.h.

◆ iterator

template<int BITS_PER_WORD = 4096 * 8>
using bitdeque< BITS_PER_WORD >::iterator = Iterator<false>

Definition at line 114 of file bitdeque.h.

◆ pointer

template<int BITS_PER_WORD = 4096 * 8>
using bitdeque< BITS_PER_WORD >::pointer = void

Definition at line 116 of file bitdeque.h.

◆ reference

template<int BITS_PER_WORD = 4096 * 8>
using bitdeque< BITS_PER_WORD >::reference = typename word_type::reference

Definition at line 112 of file bitdeque.h.

◆ reverse_iterator

template<int BITS_PER_WORD = 4096 * 8>
using bitdeque< BITS_PER_WORD >::reverse_iterator = std::reverse_iterator<iterator>

Definition at line 118 of file bitdeque.h.

◆ size_type

template<int BITS_PER_WORD = 4096 * 8>
using bitdeque< BITS_PER_WORD >::size_type = std::size_t

Definition at line 110 of file bitdeque.h.

◆ value_type

template<int BITS_PER_WORD = 4096 * 8>
using bitdeque< BITS_PER_WORD >::value_type = bool

Definition at line 109 of file bitdeque.h.

◆ word_type

template<int BITS_PER_WORD = 4096 * 8>
using bitdeque< BITS_PER_WORD >::word_type = std::bitset<BITS_PER_WORD>
private

Definition at line 25 of file bitdeque.h.

Constructor & Destructor Documentation

◆ bitdeque() [1/7]

template<int BITS_PER_WORD = 4096 * 8>
bitdeque< BITS_PER_WORD >::bitdeque ( )
inlineexplicit

Construct an empty container.

Definition at line 208 of file bitdeque.h.

Here is the caller graph for this function:

◆ bitdeque() [2/7]

template<int BITS_PER_WORD = 4096 * 8>
bitdeque< BITS_PER_WORD >::bitdeque ( size_type count,
bool val )
inline

Construct a container containing count times the value of val.

Definition at line 226 of file bitdeque.h.

Here is the call graph for this function:

◆ bitdeque() [3/7]

template<int BITS_PER_WORD = 4096 * 8>
bitdeque< BITS_PER_WORD >::bitdeque ( size_t count)
inlineexplicit

Construct a container containing count false values.

Definition at line 229 of file bitdeque.h.

Here is the call graph for this function:

◆ bitdeque() [4/7]

template<int BITS_PER_WORD = 4096 * 8>
bitdeque< BITS_PER_WORD >::bitdeque ( const bitdeque< BITS_PER_WORD > & )
default

Copy constructor.

Here is the call graph for this function:

◆ bitdeque() [5/7]

template<int BITS_PER_WORD = 4096 * 8>
bitdeque< BITS_PER_WORD >::bitdeque ( bitdeque< BITS_PER_WORD > && )
defaultnoexcept

Move constructor.

Here is the call graph for this function:

◆ bitdeque() [6/7]

template<int BITS_PER_WORD = 4096 * 8>
template<typename It>
bitdeque< BITS_PER_WORD >::bitdeque ( It first,
It last )
inline

Construct a container containing the bits in [first,last).

Definition at line 308 of file bitdeque.h.

Here is the call graph for this function:

◆ bitdeque() [7/7]

template<int BITS_PER_WORD = 4096 * 8>
bitdeque< BITS_PER_WORD >::bitdeque ( std::initializer_list< bool > ilist)
inline

Construct a container containing the bits in ilist.

Definition at line 311 of file bitdeque.h.

Here is the call graph for this function:

Member Function Documentation

◆ assign() [1/3]

template<int BITS_PER_WORD = 4096 * 8>
template<typename It>
void bitdeque< BITS_PER_WORD >::assign ( It first,
It last )
inline

Set the container equal to the bits in [first,last).

Definition at line 278 of file bitdeque.h.

Here is the call graph for this function:

◆ assign() [2/3]

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::assign ( size_type count,
bool val )
inline

Set the container equal to count times the value of val.

Definition at line 211 of file bitdeque.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ assign() [3/3]

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::assign ( std::initializer_list< bool > ilist)
inline

Set the container equal to the bits in ilist.

Definition at line 289 of file bitdeque.h.

Here is the call graph for this function:

◆ at() [1/2]

template<int BITS_PER_WORD = 4096 * 8>
reference bitdeque< BITS_PER_WORD >::at ( size_type position)
inline

Definition at line 314 of file bitdeque.h.

Here is the call graph for this function:

◆ at() [2/2]

template<int BITS_PER_WORD = 4096 * 8>
const_reference bitdeque< BITS_PER_WORD >::at ( size_type position) const
inline

Definition at line 319 of file bitdeque.h.

Here is the call graph for this function:

◆ back() [1/2]

template<int BITS_PER_WORD = 4096 * 8>
reference bitdeque< BITS_PER_WORD >::back ( )
inline

Definition at line 330 of file bitdeque.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ back() [2/2]

template<int BITS_PER_WORD = 4096 * 8>
const_reference bitdeque< BITS_PER_WORD >::back ( ) const
inline

Definition at line 331 of file bitdeque.h.

Here is the call graph for this function:

◆ begin() [1/2]

template<int BITS_PER_WORD = 4096 * 8>
const_iterator bitdeque< BITS_PER_WORD >::begin ( ) const
inlinenoexcept

Definition at line 246 of file bitdeque.h.

◆ begin() [2/2]

template<int BITS_PER_WORD = 4096 * 8>
iterator bitdeque< BITS_PER_WORD >::begin ( )
inlinenoexcept

Definition at line 244 of file bitdeque.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ cbegin()

template<int BITS_PER_WORD = 4096 * 8>
const_iterator bitdeque< BITS_PER_WORD >::cbegin ( ) const
inlinenoexcept

Definition at line 247 of file bitdeque.h.

Here is the caller graph for this function:

◆ cend()

template<int BITS_PER_WORD = 4096 * 8>
const_iterator bitdeque< BITS_PER_WORD >::cend ( ) const
inlinenoexcept

Definition at line 249 of file bitdeque.h.

Here is the caller graph for this function:

◆ clear()

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::clear ( )
inlinenoexcept

Empty the container.

Definition at line 340 of file bitdeque.h.

◆ crbegin()

template<int BITS_PER_WORD = 4096 * 8>
const_reverse_iterator bitdeque< BITS_PER_WORD >::crbegin ( ) const
inlinenoexcept

Definition at line 253 of file bitdeque.h.

Here is the call graph for this function:

◆ crend()

template<int BITS_PER_WORD = 4096 * 8>
const_reverse_iterator bitdeque< BITS_PER_WORD >::crend ( ) const
inlinenoexcept

Definition at line 255 of file bitdeque.h.

Here is the call graph for this function:

◆ emplace()

template<int BITS_PER_WORD = 4096 * 8>
iterator bitdeque< BITS_PER_WORD >::emplace ( const_iterator pos,
bool val )
inline

Definition at line 436 of file bitdeque.h.

Here is the call graph for this function:

◆ emplace_back()

template<int BITS_PER_WORD = 4096 * 8>
reference bitdeque< BITS_PER_WORD >::emplace_back ( bool val)
inline

Definition at line 352 of file bitdeque.h.

Here is the call graph for this function:

◆ emplace_front()

template<int BITS_PER_WORD = 4096 * 8>
reference bitdeque< BITS_PER_WORD >::emplace_front ( bool val)
inline

Definition at line 366 of file bitdeque.h.

Here is the call graph for this function:

◆ empty()

template<int BITS_PER_WORD = 4096 * 8>
bool bitdeque< BITS_PER_WORD >::empty ( ) const
inlinenoexcept

Determine whether the container is empty.

Definition at line 261 of file bitdeque.h.

◆ end() [1/2]

template<int BITS_PER_WORD = 4096 * 8>
const_iterator bitdeque< BITS_PER_WORD >::end ( ) const
inlinenoexcept

Definition at line 248 of file bitdeque.h.

◆ end() [2/2]

template<int BITS_PER_WORD = 4096 * 8>
iterator bitdeque< BITS_PER_WORD >::end ( )
inlinenoexcept

Definition at line 245 of file bitdeque.h.

Here is the caller graph for this function:

◆ erase() [1/4]

template<int BITS_PER_WORD = 4096 * 8>
iterator bitdeque< BITS_PER_WORD >::erase ( const_iterator first,
const_iterator last )
inline

Definition at line 406 of file bitdeque.h.

Here is the call graph for this function:

◆ erase() [2/4]

template<int BITS_PER_WORD = 4096 * 8>
iterator bitdeque< BITS_PER_WORD >::erase ( const_iterator pos)
inline

Definition at line 423 of file bitdeque.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erase() [3/4]

template<int BITS_PER_WORD = 4096 * 8>
iterator bitdeque< BITS_PER_WORD >::erase ( iterator first,
iterator last )
inline

Definition at line 422 of file bitdeque.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erase() [4/4]

template<int BITS_PER_WORD = 4096 * 8>
iterator bitdeque< BITS_PER_WORD >::erase ( iterator pos)
inline

Definition at line 424 of file bitdeque.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ erase_back()

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::erase_back ( size_type n)
inlineprivate

Shrink the container by n bits, removing from the end.

Definition at line 132 of file bitdeque.h.

Here is the caller graph for this function:

◆ erase_front()

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::erase_front ( size_type n)
inlineprivate

Shrink the container by n bits, removing from the beginning.

Definition at line 163 of file bitdeque.h.

Here is the caller graph for this function:

◆ extend_back()

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::extend_back ( size_type n)
inlineprivate

Extend the container by n bits, adding at the end.

Definition at line 151 of file bitdeque.h.

Here is the caller graph for this function:

◆ extend_front()

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::extend_front ( size_type n)
inlineprivate

Extend the container by n bits, adding at the beginning.

Definition at line 182 of file bitdeque.h.

Here is the caller graph for this function:

◆ front() [1/2]

template<int BITS_PER_WORD = 4096 * 8>
reference bitdeque< BITS_PER_WORD >::front ( )
inline

Definition at line 328 of file bitdeque.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ front() [2/2]

template<int BITS_PER_WORD = 4096 * 8>
const_reference bitdeque< BITS_PER_WORD >::front ( ) const
inline

Definition at line 329 of file bitdeque.h.

Here is the call graph for this function:

◆ insert() [1/3]

template<int BITS_PER_WORD = 4096 * 8>
iterator bitdeque< BITS_PER_WORD >::insert ( const_iterator pos,
bool val )
inline

Definition at line 427 of file bitdeque.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert() [2/3]

template<int BITS_PER_WORD = 4096 * 8>
template<typename It>
iterator bitdeque< BITS_PER_WORD >::insert ( const_iterator pos,
It first,
It last )
inline

Definition at line 450 of file bitdeque.h.

Here is the call graph for this function:

◆ insert() [3/3]

template<int BITS_PER_WORD = 4096 * 8>
iterator bitdeque< BITS_PER_WORD >::insert ( const_iterator pos,
size_type count,
bool val )
inline

Definition at line 438 of file bitdeque.h.

Here is the call graph for this function:

◆ insert_zeroes()

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::insert_zeroes ( size_type before,
size_type count )
inlineprivate

Insert a sequence of falses anywhere in the container.

Definition at line 194 of file bitdeque.h.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ max_size()

template<int BITS_PER_WORD = 4096 * 8>
size_type bitdeque< BITS_PER_WORD >::max_size ( ) const
inlinenoexcept

Return the maximum size of the container.

Definition at line 267 of file bitdeque.h.

◆ operator=() [1/3]

template<int BITS_PER_WORD = 4096 * 8>
bitdeque & bitdeque< BITS_PER_WORD >::operator= ( bitdeque< BITS_PER_WORD > && other)
defaultnoexcept

Move assignment operator.

Here is the call graph for this function:

◆ operator=() [2/3]

template<int BITS_PER_WORD = 4096 * 8>
bitdeque & bitdeque< BITS_PER_WORD >::operator= ( const bitdeque< BITS_PER_WORD > & other)
default

Copy assignment operator.

Here is the call graph for this function:

◆ operator=() [3/3]

template<int BITS_PER_WORD = 4096 * 8>
bitdeque & bitdeque< BITS_PER_WORD >::operator= ( std::initializer_list< bool > ilist)
inline

Set the container equal to the bits in ilist.

Definition at line 300 of file bitdeque.h.

Here is the call graph for this function:

◆ operator[]() [1/2]

template<int BITS_PER_WORD = 4096 * 8>
reference bitdeque< BITS_PER_WORD >::operator[] ( size_type position)
inline

Definition at line 326 of file bitdeque.h.

Here is the call graph for this function:

◆ operator[]() [2/2]

template<int BITS_PER_WORD = 4096 * 8>
const_reference bitdeque< BITS_PER_WORD >::operator[] ( size_type position) const
inline

Definition at line 327 of file bitdeque.h.

Here is the call graph for this function:

◆ pop_back()

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::pop_back ( )
inline

Definition at line 375 of file bitdeque.h.

Here is the call graph for this function:

◆ pop_front()

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::pop_front ( )
inline

Definition at line 381 of file bitdeque.h.

Here is the call graph for this function:

◆ push_back()

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::push_back ( bool val)
inline

Definition at line 347 of file bitdeque.h.

Here is the call graph for this function:

◆ push_front()

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::push_front ( bool val)
inline

Definition at line 361 of file bitdeque.h.

Here is the call graph for this function:

◆ rbegin() [1/2]

template<int BITS_PER_WORD = 4096 * 8>
const_reverse_iterator bitdeque< BITS_PER_WORD >::rbegin ( ) const
inlinenoexcept

Definition at line 252 of file bitdeque.h.

Here is the call graph for this function:

◆ rbegin() [2/2]

template<int BITS_PER_WORD = 4096 * 8>
reverse_iterator bitdeque< BITS_PER_WORD >::rbegin ( )
inlinenoexcept

Definition at line 250 of file bitdeque.h.

Here is the call graph for this function:

◆ rend() [1/2]

template<int BITS_PER_WORD = 4096 * 8>
const_reverse_iterator bitdeque< BITS_PER_WORD >::rend ( ) const
inlinenoexcept

Definition at line 254 of file bitdeque.h.

Here is the call graph for this function:

◆ rend() [2/2]

template<int BITS_PER_WORD = 4096 * 8>
reverse_iterator bitdeque< BITS_PER_WORD >::rend ( )
inlinenoexcept

Definition at line 251 of file bitdeque.h.

Here is the call graph for this function:

◆ resize()

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::resize ( size_type n)
inline

Resize the container.

Definition at line 387 of file bitdeque.h.

Here is the call graph for this function:

◆ shrink_to_fit()

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::shrink_to_fit ( )
inline

Release unused memory.

Definition at line 334 of file bitdeque.h.

◆ size()

template<int BITS_PER_WORD = 4096 * 8>
size_type bitdeque< BITS_PER_WORD >::size ( ) const
inlinenoexcept

Count the number of bits in the container.

Definition at line 258 of file bitdeque.h.

Here is the caller graph for this function:

◆ swap()

template<int BITS_PER_WORD = 4096 * 8>
void bitdeque< BITS_PER_WORD >::swap ( bitdeque< BITS_PER_WORD > & other)
inlinenoexcept

Definition at line 397 of file bitdeque.h.

Here is the call graph for this function:

◆ Iterator

template<int BITS_PER_WORD = 4096 * 8>
template<bool Const>
friend class Iterator
friend

Definition at line 31 of file bitdeque.h.

◆ swap

template<int BITS_PER_WORD = 4096 * 8>
void swap ( bitdeque< BITS_PER_WORD > & b1,
bitdeque< BITS_PER_WORD > & b2 )
friend

Definition at line 403 of file bitdeque.h.

Member Data Documentation

◆ m_deque

template<int BITS_PER_WORD = 4096 * 8>
deque_type bitdeque< BITS_PER_WORD >::m_deque
private

Deque of bitsets storing the actual bit data.

Definition at line 123 of file bitdeque.h.

◆ m_pad_begin

template<int BITS_PER_WORD = 4096 * 8>
int bitdeque< BITS_PER_WORD >::m_pad_begin
private

Number of unused bits at the front of m_deque.front().

Definition at line 126 of file bitdeque.h.

◆ m_pad_end

template<int BITS_PER_WORD = 4096 * 8>
int bitdeque< BITS_PER_WORD >::m_pad_end
private

Number of unused bits at the back of m_deque.back().

Definition at line 129 of file bitdeque.h.


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