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

A bitset implementation backed by a single integer 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 IntBitSet () noexcept
 Construct an all-zero bitset. More...
 
constexpr IntBitSet (const IntBitSet &) noexcept=default
 Copy construct a bitset. More...
 
constexpr IntBitSet (std::initializer_list< unsigned > ilist) noexcept
 Construct from a list of values. More...
 
constexpr IntBitSetoperator= (const IntBitSet &) noexcept=default
 Copy assign a bitset. More...
 
constexpr IntBitSetoperator= (std::initializer_list< unsigned > ilist) noexcept
 Assign from a list of positions (which will be made true, all others false). More...
 
constexpr void Set (unsigned pos) noexcept
 Set a bit to 1. More...
 
constexpr void Set (unsigned pos, bool val) noexcept
 Set a bit to the specified value. More...
 
constexpr void Reset (unsigned pos) noexcept
 Set a bit to 0. More...
 
constexpr bool operator[] (unsigned pos) const noexcept
 Retrieve a bit at the given position. More...
 
constexpr unsigned Count () const noexcept
 Compute the number of 1 bits in the bitset. More...
 
constexpr bool None () const noexcept
 Check if all bits are 0. More...
 
constexpr bool Any () const noexcept
 Check if any bits are 1. More...
 
constexpr Iterator begin () const noexcept
 Return an object that iterates over all 1 bits (++ and * only allowed when != end()). More...
 
constexpr IteratorEnd end () const noexcept
 Return a dummy object to compare Iterators with. More...
 
constexpr unsigned First () const noexcept
 Find the first element (requires Any()). More...
 
constexpr unsigned Last () const noexcept
 Find the last element (requires Any()). More...
 
constexpr IntBitSetoperator|= (const IntBitSet &a) noexcept
 Set this object's bits to be the binary AND between respective bits from this and a. More...
 
constexpr IntBitSetoperator&= (const IntBitSet &a) noexcept
 Set this object's bits to be the binary OR between respective bits from this and a. More...
 
constexpr IntBitSetoperator-= (const IntBitSet &a) noexcept
 Set this object's bits to be the binary AND NOT between respective bits from this and a. More...
 
constexpr IntBitSetoperator^= (const IntBitSet &a) noexcept
 Set this object's bits to be the binary XOR between respective bits from this as a. More...
 
constexpr bool Overlaps (const IntBitSet &a) const noexcept
 Check if the intersection between two sets is non-empty. More...
 
constexpr bool IsSupersetOf (const IntBitSet &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 IntBitSet &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 IntBitSet Singleton (unsigned i) noexcept
 Construct a bitset with the singleton i. More...
 
static constexpr IntBitSet 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 Member Functions

 IntBitSet (I val) noexcept
 Internal constructor with a given integer as contents. More...
 

Private Attributes

m_val
 Integer whose bits represent this bitset. More...
 

Static Private Attributes

static constexpr unsigned MAX_SIZE = std::numeric_limits<I>::digits
 The maximum number of bits this bitset supports. More...
 

Friends

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

Detailed Description

template<typename I>
class bitset_detail::IntBitSet< I >

A bitset implementation backed by a single integer of type I.

Definition at line 62 of file bitset.h.

Constructor & Destructor Documentation

◆ IntBitSet() [1/4]

template<typename I >
bitset_detail::IntBitSet< I >::IntBitSet ( val)
inlineprivatenoexcept

Internal constructor with a given integer as contents.

Definition at line 71 of file bitset.h.

◆ IntBitSet() [2/4]

template<typename I >
constexpr bitset_detail::IntBitSet< I >::IntBitSet ( )
inlineconstexprnoexcept

Construct an all-zero bitset.

Definition at line 119 of file bitset.h.

Here is the caller graph for this function:

◆ IntBitSet() [3/4]

template<typename I >
constexpr bitset_detail::IntBitSet< I >::IntBitSet ( const IntBitSet< I > &  )
constexprdefaultnoexcept

Copy construct a bitset.

◆ IntBitSet() [4/4]

template<typename I >
constexpr bitset_detail::IntBitSet< I >::IntBitSet ( std::initializer_list< unsigned >  ilist)
inlineconstexprnoexcept

Construct from a list of values.

Definition at line 123 of file bitset.h.

Here is the call graph for this function:

Member Function Documentation

◆ Any()

template<typename I >
constexpr bool bitset_detail::IntBitSet< I >::Any ( ) const
inlineconstexprnoexcept

Check if any bits are 1.

Definition at line 181 of file bitset.h.

Here is the call graph for this function:

◆ begin()

template<typename I >
constexpr Iterator bitset_detail::IntBitSet< I >::begin ( ) const
inlineconstexprnoexcept

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

Definition at line 183 of file bitset.h.

◆ Count()

template<typename I >
constexpr unsigned bitset_detail::IntBitSet< I >::Count ( ) const
inlineconstexprnoexcept

Compute the number of 1 bits in the bitset.

Definition at line 175 of file bitset.h.

Here is the call graph for this function:

◆ end()

template<typename I >
constexpr IteratorEnd bitset_detail::IntBitSet< I >::end ( ) const
inlineconstexprnoexcept

Return a dummy object to compare Iterators with.

Definition at line 185 of file bitset.h.

◆ Fill()

template<typename I >
static constexpr IntBitSet bitset_detail::IntBitSet< I >::Fill ( unsigned  count)
inlinestaticconstexprnoexcept

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

Definition at line 143 of file bitset.h.

◆ First()

template<typename I >
constexpr unsigned bitset_detail::IntBitSet< I >::First ( ) const
inlineconstexprnoexcept

Find the first element (requires Any()).

Definition at line 187 of file bitset.h.

◆ IsSubsetOf()

template<typename I >
constexpr bool bitset_detail::IntBitSet< I >::IsSubsetOf ( const IntBitSet< I > &  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 221 of file bitset.h.

◆ IsSupersetOf()

template<typename I >
constexpr bool bitset_detail::IntBitSet< I >::IsSupersetOf ( const IntBitSet< I > &  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 219 of file bitset.h.

◆ Last()

template<typename I >
constexpr unsigned bitset_detail::IntBitSet< I >::Last ( ) const
inlineconstexprnoexcept

Find the last element (requires Any()).

Definition at line 193 of file bitset.h.

◆ None()

template<typename I >
constexpr bool bitset_detail::IntBitSet< I >::None ( ) const
inlineconstexprnoexcept

Check if all bits are 0.

Definition at line 179 of file bitset.h.

Here is the caller graph for this function:

◆ operator&=()

template<typename I >
constexpr IntBitSet & bitset_detail::IntBitSet< I >::operator&= ( const IntBitSet< I > &  a)
inlineconstexprnoexcept

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

Definition at line 201 of file bitset.h.

◆ operator-=()

template<typename I >
constexpr IntBitSet & bitset_detail::IntBitSet< I >::operator-= ( const IntBitSet< I > &  a)
inlineconstexprnoexcept

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

Definition at line 203 of file bitset.h.

◆ operator=() [1/2]

template<typename I >
constexpr IntBitSet & bitset_detail::IntBitSet< I >::operator= ( const IntBitSet< I > &  )
constexprdefaultnoexcept

Copy assign a bitset.

◆ operator=() [2/2]

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

Assign from a list of positions (which will be made true, all others false).

Definition at line 130 of file bitset.h.

Here is the call graph for this function:

◆ operator[]()

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

Retrieve a bit at the given position.

Definition at line 169 of file bitset.h.

◆ operator^=()

template<typename I >
constexpr IntBitSet & bitset_detail::IntBitSet< I >::operator^= ( const IntBitSet< I > &  a)
inlineconstexprnoexcept

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

Definition at line 205 of file bitset.h.

◆ operator|=()

template<typename I >
constexpr IntBitSet & bitset_detail::IntBitSet< I >::operator|= ( const IntBitSet< I > &  a)
inlineconstexprnoexcept

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

Definition at line 199 of file bitset.h.

◆ Overlaps()

template<typename I >
constexpr bool bitset_detail::IntBitSet< I >::Overlaps ( const IntBitSet< I > &  a) const
inlineconstexprnoexcept

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

Definition at line 207 of file bitset.h.

◆ Reset()

template<typename I >
constexpr void bitset_detail::IntBitSet< I >::Reset ( unsigned  pos)
inlineconstexprnoexcept

Set a bit to 0.

Definition at line 163 of file bitset.h.

◆ Set() [1/2]

template<typename I >
constexpr void bitset_detail::IntBitSet< I >::Set ( unsigned  pos)
inlineconstexprnoexcept

Set a bit to 1.

Definition at line 151 of file bitset.h.

Here is the caller graph for this function:

◆ Set() [2/2]

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

Set a bit to the specified value.

Definition at line 157 of file bitset.h.

◆ Singleton()

template<typename I >
static constexpr IntBitSet bitset_detail::IntBitSet< I >::Singleton ( unsigned  i)
inlinestaticconstexprnoexcept

Construct a bitset with the singleton i.

Definition at line 137 of file bitset.h.

Here is the call graph for this function:

◆ Size()

template<typename I >
static constexpr unsigned bitset_detail::IntBitSet< I >::Size ( )
inlinestaticconstexprnoexcept

Return the number of bits that this object holds.

Definition at line 177 of file bitset.h.

Friends And Related Function Documentation

◆ operator&

template<typename I >
constexpr IntBitSet operator& ( const IntBitSet< I > &  a,
const IntBitSet< I > &  b 
)
friend

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

Definition at line 209 of file bitset.h.

◆ operator-

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

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

Definition at line 213 of file bitset.h.

◆ operator==

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

Check if bitset a and bitset b are identical.

◆ operator^

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

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

Definition at line 215 of file bitset.h.

◆ operator|

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

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

Definition at line 211 of file bitset.h.

◆ swap

template<typename I >
constexpr void swap ( IntBitSet< I > &  a,
IntBitSet< I > &  b 
)
friend

Swap two bitsets.

Definition at line 223 of file bitset.h.

Member Data Documentation

◆ m_val

template<typename I >
I bitset_detail::IntBitSet< I >::m_val
private

Integer whose bits represent this bitset.

Definition at line 69 of file bitset.h.

◆ MAX_SIZE

template<typename I >
constexpr unsigned bitset_detail::IntBitSet< I >::MAX_SIZE = std::numeric_limits<I>::digits
staticconstexprprivate

The maximum number of bits this bitset supports.

Definition at line 67 of file bitset.h.


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