Bitcoin Core 28.99.0
P2P Digital Currency
Classes | Public Member Functions | Static Public Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
bitset_detail::MultiIntBitSet< I, N > Class Template Reference

A bitset implementation backed by N integers of type I. More...

#include <bitset.h>

Classes

class  Iterator
 Iterator type returned by begin(), which efficiently iterates all 1 positions. More...
 
class  IteratorEnd
 Dummy type to return using end(). More...
 

Public Member Functions

constexpr MultiIntBitSet () noexcept
 Construct an all-zero bitset. More...
 
constexpr MultiIntBitSet (const MultiIntBitSet &) noexcept=default
 Copy construct a bitset. More...
 
constexpr MultiIntBitSetoperator= (const MultiIntBitSet &) noexcept=default
 Copy assign a bitset. More...
 
void constexpr Set (unsigned pos) noexcept
 Set a bit to 1. More...
 
void constexpr Set (unsigned pos, bool val) noexcept
 Set a bit to the specified value. More...
 
constexpr MultiIntBitSet (std::initializer_list< unsigned > ilist) noexcept
 Construct a bitset from a list of values. More...
 
constexpr MultiIntBitSetoperator= (std::initializer_list< unsigned > ilist) noexcept
 Set a bitset to a list of values. More...
 
void constexpr Reset (unsigned pos) noexcept
 Set a bit to 0. More...
 
bool constexpr operator[] (unsigned pos) const noexcept
 Retrieve a bit at the given position. More...
 
unsigned constexpr Count () const noexcept
 Compute the number of 1 bits in the bitset. More...
 
bool constexpr None () const noexcept
 Check if all bits are 0. More...
 
bool constexpr Any () const noexcept
 Check if any bits are 1. More...
 
Iterator constexpr begin () const noexcept
 Return an object that iterates over all 1 bits (++ and * only allowed when != end()). More...
 
IteratorEnd constexpr end () const noexcept
 Return a dummy object to compare Iterators with. More...
 
unsigned constexpr First () const noexcept
 Find the first element (requires Any()). More...
 
unsigned constexpr Last () const noexcept
 Find the last element (requires Any()). More...
 
constexpr MultiIntBitSetoperator|= (const MultiIntBitSet &a) noexcept
 Set this object's bits to be the binary OR between respective bits from this and a. More...
 
constexpr MultiIntBitSetoperator&= (const MultiIntBitSet &a) noexcept
 Set this object's bits to be the binary AND between respective bits from this and a. More...
 
constexpr MultiIntBitSetoperator-= (const MultiIntBitSet &a) noexcept
 Set this object's bits to be the binary AND NOT between respective bits from this and a. More...
 
constexpr MultiIntBitSetoperator^= (const MultiIntBitSet &a) noexcept
 Set this object's bits to be the binary XOR between respective bits from this and a. More...
 
constexpr bool Overlaps (const MultiIntBitSet &a) const noexcept
 Check whether the intersection between two sets is non-empty. More...
 
constexpr bool IsSupersetOf (const MultiIntBitSet &a) const noexcept
 Check if bitset a is a superset of bitset b (= every 1 bit in b is also in a). More...
 
constexpr bool IsSubsetOf (const MultiIntBitSet &a) const noexcept
 Check if bitset a is a subset of bitset b (= every 1 bit in a is also in b). More...
 

Static Public Member Functions

static constexpr MultiIntBitSet Singleton (unsigned pos) noexcept
 Construct a bitset with the singleton pos. More...
 
static constexpr MultiIntBitSet Fill (unsigned count) noexcept
 Construct a bitset with bits 0..count-1 (inclusive) set to 1. More...
 
static constexpr unsigned Size () noexcept
 Return the number of bits that this object holds. More...
 

Private Attributes

std::array< I, N > m_val
 Array whose member integers store the bits of the set. More...
 

Static Private Attributes

static constexpr unsigned LIMB_BITS = std::numeric_limits<I>::digits
 The number of bits per integer. More...
 
static constexpr unsigned MAX_SIZE = LIMB_BITS * N
 Number of elements this set type supports. More...
 

Friends

constexpr MultiIntBitSet operator& (const MultiIntBitSet &a, const MultiIntBitSet &b) noexcept
 Return an object with the binary AND between respective bits from a and b. More...
 
constexpr MultiIntBitSet operator| (const MultiIntBitSet &a, const MultiIntBitSet &b) noexcept
 Return an object with the binary OR between respective bits from a and b. More...
 
constexpr MultiIntBitSet operator- (const MultiIntBitSet &a, const MultiIntBitSet &b) noexcept
 Return an object with the binary AND NOT between respective bits from a and b. More...
 
constexpr MultiIntBitSet operator^ (const MultiIntBitSet &a, const MultiIntBitSet &b) noexcept
 Return an object with the binary XOR between respective bits from a and b. More...
 
constexpr bool operator== (const MultiIntBitSet &a, const MultiIntBitSet &b) noexcept=default
 Check if bitset a and bitset b are identical. More...
 
constexpr void swap (MultiIntBitSet &a, MultiIntBitSet &b) noexcept
 Swap two bitsets. More...
 

Detailed Description

template<typename I, unsigned N>
class bitset_detail::MultiIntBitSet< I, N >

A bitset implementation backed by N integers of type I.

Definition at line 228 of file bitset.h.

Constructor & Destructor Documentation

◆ MultiIntBitSet() [1/3]

template<typename I , unsigned N>
constexpr bitset_detail::MultiIntBitSet< I, N >::MultiIntBitSet ( )
inlineconstexprnoexcept

Construct an all-zero bitset.

Definition at line 311 of file bitset.h.

◆ MultiIntBitSet() [2/3]

template<typename I , unsigned N>
constexpr bitset_detail::MultiIntBitSet< I, N >::MultiIntBitSet ( const MultiIntBitSet< I, N > &  )
constexprdefaultnoexcept

Copy construct a bitset.

◆ MultiIntBitSet() [3/3]

template<typename I , unsigned N>
constexpr bitset_detail::MultiIntBitSet< I, N >::MultiIntBitSet ( std::initializer_list< unsigned >  ilist)
inlineconstexprnoexcept

Construct a bitset from a list of values.

Definition at line 330 of file bitset.h.

Member Function Documentation

◆ Any()

template<typename I , unsigned N>
bool constexpr bitset_detail::MultiIntBitSet< I, N >::Any ( ) const
inlineconstexprnoexcept

Check if any bits are 1.

Definition at line 394 of file bitset.h.

Here is the call graph for this function:

◆ begin()

template<typename I , unsigned N>
Iterator constexpr bitset_detail::MultiIntBitSet< I, N >::begin ( ) const
inlineconstexprnoexcept

Return an object that iterates over all 1 bits (++ and * only allowed when != end()).

Definition at line 396 of file bitset.h.

◆ Count()

template<typename I , unsigned N>
unsigned constexpr bitset_detail::MultiIntBitSet< I, N >::Count ( ) const
inlineconstexprnoexcept

Compute the number of 1 bits in the bitset.

Definition at line 379 of file bitset.h.

Here is the call graph for this function:

◆ end()

template<typename I , unsigned N>
IteratorEnd constexpr bitset_detail::MultiIntBitSet< I, N >::end ( ) const
inlineconstexprnoexcept

Return a dummy object to compare Iterators with.

Definition at line 398 of file bitset.h.

◆ Fill()

template<typename I , unsigned N>
static constexpr MultiIntBitSet bitset_detail::MultiIntBitSet< I, N >::Fill ( unsigned  count)
inlinestaticconstexprnoexcept

Construct a bitset with bits 0..count-1 (inclusive) set to 1.

Definition at line 362 of file bitset.h.

◆ First()

template<typename I , unsigned N>
unsigned constexpr bitset_detail::MultiIntBitSet< I, N >::First ( ) const
inlineconstexprnoexcept

Find the first element (requires Any()).

Definition at line 400 of file bitset.h.

◆ IsSubsetOf()

template<typename I , unsigned N>
constexpr bool bitset_detail::MultiIntBitSet< I, N >::IsSubsetOf ( const MultiIntBitSet< I, N > &  a) const
inlineconstexprnoexcept

Check if bitset a is a subset of bitset b (= every 1 bit in a is also in b).

Definition at line 504 of file bitset.h.

◆ IsSupersetOf()

template<typename I , unsigned N>
constexpr bool bitset_detail::MultiIntBitSet< I, N >::IsSupersetOf ( const MultiIntBitSet< I, N > &  a) const
inlineconstexprnoexcept

Check if bitset a is a superset of bitset b (= every 1 bit in b is also in a).

Definition at line 496 of file bitset.h.

◆ Last()

template<typename I , unsigned N>
unsigned constexpr bitset_detail::MultiIntBitSet< I, N >::Last ( ) const
inlineconstexprnoexcept

Find the last element (requires Any()).

Definition at line 410 of file bitset.h.

◆ None()

template<typename I , unsigned N>
bool constexpr bitset_detail::MultiIntBitSet< I, N >::None ( ) const
inlineconstexprnoexcept

Check if all bits are 0.

Definition at line 386 of file bitset.h.

Here is the caller graph for this function:

◆ operator&=()

template<typename I , unsigned N>
constexpr MultiIntBitSet & bitset_detail::MultiIntBitSet< I, N >::operator&= ( const MultiIntBitSet< I, N > &  a)
inlineconstexprnoexcept

Set this object's bits to be the binary AND between respective bits from this and a.

Definition at line 428 of file bitset.h.

◆ operator-=()

template<typename I , unsigned N>
constexpr MultiIntBitSet & bitset_detail::MultiIntBitSet< I, N >::operator-= ( const MultiIntBitSet< I, N > &  a)
inlineconstexprnoexcept

Set this object's bits to be the binary AND NOT between respective bits from this and a.

Definition at line 436 of file bitset.h.

◆ operator=() [1/2]

template<typename I , unsigned N>
constexpr MultiIntBitSet & bitset_detail::MultiIntBitSet< I, N >::operator= ( const MultiIntBitSet< I, N > &  )
constexprdefaultnoexcept

Copy assign a bitset.

◆ operator=() [2/2]

template<typename I , unsigned N>
constexpr MultiIntBitSet & bitset_detail::MultiIntBitSet< I, N >::operator= ( std::initializer_list< unsigned >  ilist)
inlineconstexprnoexcept

Set a bitset to a list of values.

Definition at line 335 of file bitset.h.

Here is the call graph for this function:

◆ operator[]()

template<typename I , unsigned N>
bool constexpr bitset_detail::MultiIntBitSet< I, N >::operator[] ( unsigned  pos) const
inlineconstexprnoexcept

Retrieve a bit at the given position.

Definition at line 348 of file bitset.h.

◆ operator^=()

template<typename I , unsigned N>
constexpr MultiIntBitSet & bitset_detail::MultiIntBitSet< I, N >::operator^= ( const MultiIntBitSet< I, N > &  a)
inlineconstexprnoexcept

Set this object's bits to be the binary XOR between respective bits from this and a.

Definition at line 444 of file bitset.h.

◆ operator|=()

template<typename I , unsigned N>
constexpr MultiIntBitSet & bitset_detail::MultiIntBitSet< I, N >::operator|= ( const MultiIntBitSet< I, N > &  a)
inlineconstexprnoexcept

Set this object's bits to be the binary OR between respective bits from this and a.

Definition at line 420 of file bitset.h.

◆ Overlaps()

template<typename I , unsigned N>
constexpr bool bitset_detail::MultiIntBitSet< I, N >::Overlaps ( const MultiIntBitSet< I, N > &  a) const
inlineconstexprnoexcept

Check whether the intersection between two sets is non-empty.

Definition at line 452 of file bitset.h.

◆ Reset()

template<typename I , unsigned N>
void constexpr bitset_detail::MultiIntBitSet< I, N >::Reset ( unsigned  pos)
inlineconstexprnoexcept

Set a bit to 0.

Definition at line 342 of file bitset.h.

◆ Set() [1/2]

template<typename I , unsigned N>
void constexpr bitset_detail::MultiIntBitSet< I, N >::Set ( unsigned  pos)
inlineconstexprnoexcept

Set a bit to 1.

Definition at line 317 of file bitset.h.

Here is the caller graph for this function:

◆ Set() [2/2]

template<typename I , unsigned N>
void constexpr bitset_detail::MultiIntBitSet< I, N >::Set ( unsigned  pos,
bool  val 
)
inlineconstexprnoexcept

Set a bit to the specified value.

Definition at line 323 of file bitset.h.

◆ Singleton()

template<typename I , unsigned N>
static constexpr MultiIntBitSet bitset_detail::MultiIntBitSet< I, N >::Singleton ( unsigned  pos)
inlinestaticconstexprnoexcept

Construct a bitset with the singleton pos.

Definition at line 354 of file bitset.h.

◆ Size()

template<typename I , unsigned N>
static constexpr unsigned bitset_detail::MultiIntBitSet< I, N >::Size ( )
inlinestaticconstexprnoexcept

Return the number of bits that this object holds.

Definition at line 377 of file bitset.h.

Friends And Related Function Documentation

◆ operator&

template<typename I , unsigned N>
constexpr MultiIntBitSet operator& ( const MultiIntBitSet< I, N > &  a,
const MultiIntBitSet< I, N > &  b 
)
friend

Return an object with the binary AND between respective bits from a and b.

Definition at line 460 of file bitset.h.

◆ operator-

template<typename I , unsigned N>
constexpr MultiIntBitSet operator- ( const MultiIntBitSet< I, N > &  a,
const MultiIntBitSet< I, N > &  b 
)
friend

Return an object with the binary AND NOT between respective bits from a and b.

Definition at line 478 of file bitset.h.

◆ operator==

template<typename I , unsigned N>
constexpr bool operator== ( const MultiIntBitSet< I, N > &  a,
const MultiIntBitSet< I, N > &  b 
)
friend

Check if bitset a and bitset b are identical.

◆ operator^

template<typename I , unsigned N>
constexpr MultiIntBitSet operator^ ( const MultiIntBitSet< I, N > &  a,
const MultiIntBitSet< I, N > &  b 
)
friend

Return an object with the binary XOR between respective bits from a and b.

Definition at line 487 of file bitset.h.

◆ operator|

template<typename I , unsigned N>
constexpr MultiIntBitSet operator| ( const MultiIntBitSet< I, N > &  a,
const MultiIntBitSet< I, N > &  b 
)
friend

Return an object with the binary OR between respective bits from a and b.

Definition at line 469 of file bitset.h.

◆ swap

template<typename I , unsigned N>
constexpr void swap ( MultiIntBitSet< I, N > &  a,
MultiIntBitSet< I, N > &  b 
)
friend

Swap two bitsets.

Definition at line 514 of file bitset.h.

Member Data Documentation

◆ LIMB_BITS

template<typename I , unsigned N>
constexpr unsigned bitset_detail::MultiIntBitSet< I, N >::LIMB_BITS = std::numeric_limits<I>::digits
staticconstexprprivate

The number of bits per integer.

Definition at line 235 of file bitset.h.

◆ m_val

template<typename I , unsigned N>
std::array<I, N> bitset_detail::MultiIntBitSet< I, N >::m_val
private

Array whose member integers store the bits of the set.

Definition at line 241 of file bitset.h.

◆ MAX_SIZE

template<typename I , unsigned N>
constexpr unsigned bitset_detail::MultiIntBitSet< I, N >::MAX_SIZE = LIMB_BITS * N
staticconstexprprivate

Number of elements this set type supports.

Definition at line 237 of file bitset.h.


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