Empirical
Classes | Public Member Functions | Static Public Member Functions | Friends | List of all members
emp::BitSet< NUM_BITS > Class Template Reference

#include <BitSet.h>

Public Member Functions

 BitSet ()
 Constructor: Assume all zeroes in set. More...
 
 BitSet (const BitSet &in_set)
 Copy constructor from another BitSet. More...
 
 BitSet (Random &random, const double p1=0.5)
 Constructor to generate a random BitSet. More...
 
 ~BitSet ()=default
 Destructor. More...
 
BitSetoperator= (const BitSet< NUM_BITS > &in_set)
 Assignment operator. More...
 
void Randomize (Random &random, const double p1=0.5)
 Set all bits randomly, with a given probability of being a 1. More...
 
template<size_t NUM_BITS2>
BitSetImport (const BitSet< NUM_BITS2 > &in_set)
 Assign from a BitSet of a different size. More...
 
template<size_t NUM_BITS2>
BitSet< NUM_BITS2 > Export () const
 Convert to a Bitset of a different size. More...
 
bool operator== (const BitSet &in_set) const
 Test if two BitSet objects are identical. More...
 
bool operator< (const BitSet &in_set) const
 Compare two BitSet objects, based on the associated binary value. More...
 
bool operator<= (const BitSet &in_set) const
 Compare two BitSet objects, based on the associated binary value. More...
 
bool operator!= (const BitSet &in_set) const
 Test if two BitSet objects are different. More...
 
bool operator> (const BitSet &in_set) const
 Compare two BitSet objects, based on the associated binary value. More...
 
bool operator>= (const BitSet &in_set) const
 Compare two BitSet objects, based on the associated binary value. More...
 
bool Get (size_t index) const
 Retrieve the bit as a specified index. More...
 
void Set (size_t index, bool value)
 Set the bit as a specified index. More...
 
BitSetToggle ()
 Flip all bits in this BitSet. More...
 
BitSetToggle (size_t index)
 Flip a single bit. More...
 
BitSetToggle (size_t start, size_t end)
 Flips all the bits in a range [start, end) More...
 
uint8_t GetByte (size_t index) const
 Get the full byte starting from the bit at a specified index. More...
 
void SetByte (size_t index, uint8_t value)
 Set the full byte starting at the bit at the specified index. More...
 
uint32_t GetUInt (size_t index) const
 Get the 32-bit unsigned int; index in in 32-bit jumps (i.e., this is a field ID not bit id) More...
 
void SetUInt (size_t index, uint32_t value)
 Set the 32-bit unsigned int; index in in 32-bit jumps (i.e., this is a field ID not bit id) More...
 
uint32_t GetUIntAtBit (size_t index)
 Get the full 32-bit unsigned int starting from the bit at a specified index. More...
 
template<size_t OUT_BITS>
uint32_t GetValueAtBit (size_t index)
 Get OUT_BITS bits starting from the bit at a specified index (max 32) More...
 
bool Any () const
 Return true if ANY bits in the BitSet are one, else return false. More...
 
bool None () const
 Return true if NO bits in the BitSet are one, else return false. More...
 
bool All () const
 Return true if ALL bits in the BitSet are one, else return false. More...
 
bool operator[] (size_t index) const
 Index into a const BitSet (i.e., cannot be set this way.) More...
 
BitProxy operator[] (size_t index)
 Index into a BitSet, returning a proxy that will allow bit assignment to work. More...
 
void Clear ()
 Set all bits to zero. More...
 
void SetAll ()
 Set all bits to one. More...
 
void Print (std::ostream &out=std::cout) const
 Print all bits to the provided output stream. More...
 
void PrintArray (std::ostream &out=std::cout) const
 Print all bits from smallest to largest, as if this were an array, not a bit representation. More...
 
void PrintOneIDs (std::ostream &out=std::cout, char spacer=' ') const
 Print the locations of all one bits, using the provided spacer (default is a single space) More...
 
size_t CountOnes_Sparse () const
 Count 1's by looping through once for each bit equal to 1. More...
 
size_t CountOnes_Mixed () const
 Count 1's in semi-parallel; fastest for even 0's & 1's. More...
 
size_t CountOnes () const
 Count the number of ones in the BitSet using bit tricks for a speedup. More...
 
int FindBit () const
 Return the index of the first one in the sequence; return -1 if no ones are available. More...
 
int PopBit ()
 Return index of first one in sequence (or -1 if no ones); change this position to zero. More...
 
int FindBit (const size_t start_pos) const
 Return index of first one in sequence AFTER start_pos (or -1 if no ones) More...
 
emp::vector< size_t > GetOnes () const
 Return a vector indicating the posistions of all ones in the BitSet. More...
 
BitSet NOT () const
 Perform a Boolean NOT on this BitSet and return the result. More...
 
BitSet AND (const BitSet &set2) const
 Perform a Boolean AND with a second BitSet and return the result. More...
 
BitSet OR (const BitSet &set2) const
 Perform a Boolean OR with a second BitSet and return the result. More...
 
BitSet NAND (const BitSet &set2) const
 Perform a Boolean NAND with a second BitSet and return the result. More...
 
BitSet NOR (const BitSet &set2) const
 Perform a Boolean NOR with a second BitSet and return the result. More...
 
BitSet XOR (const BitSet &set2) const
 Perform a Boolean XOR with a second BitSet and return the result. More...
 
BitSet EQU (const BitSet &set2) const
 Perform a Boolean EQU with a second BitSet and return the result. More...
 
BitSetNOT_SELF ()
 Perform a Boolean NOT on this BitSet, store result here, and return this object. More...
 
BitSetAND_SELF (const BitSet &set2)
 Perform a Boolean AND with a second BitSet, store result here, and return this object. More...
 
BitSetOR_SELF (const BitSet &set2)
 Perform a Boolean OR with a second BitSet, store result here, and return this object. More...
 
BitSetNAND_SELF (const BitSet &set2)
 Perform a Boolean NAND with a second BitSet, store result here, and return this object. More...
 
BitSetNOR_SELF (const BitSet &set2)
 Perform a Boolean NOR with a second BitSet, store result here, and return this object. More...
 
BitSetXOR_SELF (const BitSet &set2)
 Perform a Boolean XOR with a second BitSet, store result here, and return this object. More...
 
BitSetEQU_SELF (const BitSet &set2)
 Perform a Boolean EQU with a second BitSet, store result here, and return this object. More...
 
BitSet SHIFT (const int shift_size) const
 Positive shifts go left and negative go right (0 does nothing); return result. More...
 
BitSetSHIFT_SELF (const int shift_size)
 Positive shifts go left and negative go right; store result here, and return this object. More...
 
BitSet operator~ () const
 Operator bitwise NOT... More...
 
BitSet operator& (const BitSet &ar2) const
 Operator bitwise AND... More...
 
BitSet operator| (const BitSet &ar2) const
 Operator bitwise OR... More...
 
BitSet operator^ (const BitSet &ar2) const
 Operator bitwise XOR... More...
 
BitSet operator<< (const size_t shift_size) const
 Operator shift left... More...
 
BitSet operator>> (const size_t shift_size) const
 Operator shift right... More...
 
const BitSetoperator&= (const BitSet &ar2)
 Compound operator bitwise AND... More...
 
const BitSetoperator|= (const BitSet &ar2)
 Compound operator bitwise OR... More...
 
const BitSetoperator^= (const BitSet &ar2)
 Compound operator bitwise XOR... More...
 
const BitSetoperator<<= (const size_t shift_size)
 Compound operator shift left... More...
 
const BitSetoperator>>= (const size_t shift_size)
 Compound operator shift right... More...
 
bool all () const
 Function to allow drop-in replacement with std::bitset. More...
 
bool any () const
 Function to allow drop-in replacement with std::bitset. More...
 
bool none () const
 Function to allow drop-in replacement with std::bitset. More...
 
size_t count () const
 Function to allow drop-in replacement with std::bitset. More...
 
BitSetflip ()
 Function to allow drop-in replacement with std::bitset. More...
 
BitSetflip (size_t pos)
 Function to allow drop-in replacement with std::bitset. More...
 
BitSetflip (size_t start, size_t end)
 Function to allow drop-in replacement with std::bitset. More...
 

Static Public Member Functions

static constexpr size_t GetSize ()
 How many bits are in this BitSet? More...
 
static constexpr size_t size ()
 Function to allow drop-in replacement with std::bitset. More...
 

Friends

class BitProxy
 

Detailed Description

template<size_t NUM_BITS>
class emp::BitSet< NUM_BITS >

A fixed-sized (but arbitrarily large) array of bits, and optimizes operations on those bits to be as fast as possible.

Constructor & Destructor Documentation

template<size_t NUM_BITS>
emp::BitSet< NUM_BITS >::BitSet ( )
inline

Constructor: Assume all zeroes in set.

template<size_t NUM_BITS>
emp::BitSet< NUM_BITS >::BitSet ( const BitSet< NUM_BITS > &  in_set)
inline

Copy constructor from another BitSet.

template<size_t NUM_BITS>
emp::BitSet< NUM_BITS >::BitSet ( Random random,
const double  p1 = 0.5 
)
inline

Constructor to generate a random BitSet.

template<size_t NUM_BITS>
emp::BitSet< NUM_BITS >::~BitSet ( )
default

Destructor.

Member Function Documentation

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::All ( ) const
inline

Return true if ALL bits in the BitSet are one, else return false.

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::all ( ) const
inline

Function to allow drop-in replacement with std::bitset.

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::AND ( const BitSet< NUM_BITS > &  set2) const
inline

Perform a Boolean AND with a second BitSet and return the result.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::AND_SELF ( const BitSet< NUM_BITS > &  set2)
inline

Perform a Boolean AND with a second BitSet, store result here, and return this object.

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::Any ( ) const
inline

Return true if ANY bits in the BitSet are one, else return false.

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::any ( ) const
inline

Function to allow drop-in replacement with std::bitset.

template<size_t NUM_BITS>
void emp::BitSet< NUM_BITS >::Clear ( )
inline

Set all bits to zero.

template<size_t NUM_BITS>
size_t emp::BitSet< NUM_BITS >::count ( ) const
inline

Function to allow drop-in replacement with std::bitset.

template<size_t NUM_BITS>
size_t emp::BitSet< NUM_BITS >::CountOnes ( ) const
inline

Count the number of ones in the BitSet using bit tricks for a speedup.

template<size_t NUM_BITS>
size_t emp::BitSet< NUM_BITS >::CountOnes_Mixed ( ) const
inline

Count 1's in semi-parallel; fastest for even 0's & 1's.

template<size_t NUM_BITS>
size_t emp::BitSet< NUM_BITS >::CountOnes_Sparse ( ) const
inline

Count 1's by looping through once for each bit equal to 1.

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::EQU ( const BitSet< NUM_BITS > &  set2) const
inline

Perform a Boolean EQU with a second BitSet and return the result.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::EQU_SELF ( const BitSet< NUM_BITS > &  set2)
inline

Perform a Boolean EQU with a second BitSet, store result here, and return this object.

template<size_t NUM_BITS>
template<size_t NUM_BITS2>
BitSet<NUM_BITS2> emp::BitSet< NUM_BITS >::Export ( ) const
inline

Convert to a Bitset of a different size.

template<size_t NUM_BITS>
int emp::BitSet< NUM_BITS >::FindBit ( ) const
inline

Return the index of the first one in the sequence; return -1 if no ones are available.

template<size_t NUM_BITS>
int emp::BitSet< NUM_BITS >::FindBit ( const size_t  start_pos) const
inline

Return index of first one in sequence AFTER start_pos (or -1 if no ones)

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::flip ( )
inline

Function to allow drop-in replacement with std::bitset.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::flip ( size_t  pos)
inline

Function to allow drop-in replacement with std::bitset.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::flip ( size_t  start,
size_t  end 
)
inline

Function to allow drop-in replacement with std::bitset.

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::Get ( size_t  index) const
inline

Retrieve the bit as a specified index.

template<size_t NUM_BITS>
uint8_t emp::BitSet< NUM_BITS >::GetByte ( size_t  index) const
inline

Get the full byte starting from the bit at a specified index.

template<size_t NUM_BITS>
emp::vector<size_t> emp::BitSet< NUM_BITS >::GetOnes ( ) const
inline

Return a vector indicating the posistions of all ones in the BitSet.

template<size_t NUM_BITS>
static constexpr size_t emp::BitSet< NUM_BITS >::GetSize ( )
inlinestatic

How many bits are in this BitSet?

template<size_t NUM_BITS>
uint32_t emp::BitSet< NUM_BITS >::GetUInt ( size_t  index) const
inline

Get the 32-bit unsigned int; index in in 32-bit jumps (i.e., this is a field ID not bit id)

template<size_t NUM_BITS>
uint32_t emp::BitSet< NUM_BITS >::GetUIntAtBit ( size_t  index)
inline

Get the full 32-bit unsigned int starting from the bit at a specified index.

template<size_t NUM_BITS>
template<size_t OUT_BITS>
uint32_t emp::BitSet< NUM_BITS >::GetValueAtBit ( size_t  index)
inline

Get OUT_BITS bits starting from the bit at a specified index (max 32)

template<size_t NUM_BITS>
template<size_t NUM_BITS2>
BitSet& emp::BitSet< NUM_BITS >::Import ( const BitSet< NUM_BITS2 > &  in_set)
inline

Assign from a BitSet of a different size.

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::NAND ( const BitSet< NUM_BITS > &  set2) const
inline

Perform a Boolean NAND with a second BitSet and return the result.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::NAND_SELF ( const BitSet< NUM_BITS > &  set2)
inline

Perform a Boolean NAND with a second BitSet, store result here, and return this object.

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::None ( ) const
inline

Return true if NO bits in the BitSet are one, else return false.

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::none ( ) const
inline

Function to allow drop-in replacement with std::bitset.

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::NOR ( const BitSet< NUM_BITS > &  set2) const
inline

Perform a Boolean NOR with a second BitSet and return the result.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::NOR_SELF ( const BitSet< NUM_BITS > &  set2)
inline

Perform a Boolean NOR with a second BitSet, store result here, and return this object.

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::NOT ( ) const
inline

Perform a Boolean NOT on this BitSet and return the result.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::NOT_SELF ( )
inline

Perform a Boolean NOT on this BitSet, store result here, and return this object.

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::operator!= ( const BitSet< NUM_BITS > &  in_set) const
inline

Test if two BitSet objects are different.

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::operator& ( const BitSet< NUM_BITS > &  ar2) const
inline

Operator bitwise AND...

template<size_t NUM_BITS>
const BitSet& emp::BitSet< NUM_BITS >::operator&= ( const BitSet< NUM_BITS > &  ar2)
inline

Compound operator bitwise AND...

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::operator< ( const BitSet< NUM_BITS > &  in_set) const
inline

Compare two BitSet objects, based on the associated binary value.

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::operator<< ( const size_t  shift_size) const
inline

Operator shift left...

template<size_t NUM_BITS>
const BitSet& emp::BitSet< NUM_BITS >::operator<<= ( const size_t  shift_size)
inline

Compound operator shift left...

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::operator<= ( const BitSet< NUM_BITS > &  in_set) const
inline

Compare two BitSet objects, based on the associated binary value.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::operator= ( const BitSet< NUM_BITS > &  in_set)
inline

Assignment operator.

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::operator== ( const BitSet< NUM_BITS > &  in_set) const
inline

Test if two BitSet objects are identical.

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::operator> ( const BitSet< NUM_BITS > &  in_set) const
inline

Compare two BitSet objects, based on the associated binary value.

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::operator>= ( const BitSet< NUM_BITS > &  in_set) const
inline

Compare two BitSet objects, based on the associated binary value.

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::operator>> ( const size_t  shift_size) const
inline

Operator shift right...

template<size_t NUM_BITS>
const BitSet& emp::BitSet< NUM_BITS >::operator>>= ( const size_t  shift_size)
inline

Compound operator shift right...

template<size_t NUM_BITS>
bool emp::BitSet< NUM_BITS >::operator[] ( size_t  index) const
inline

Index into a const BitSet (i.e., cannot be set this way.)

template<size_t NUM_BITS>
BitProxy emp::BitSet< NUM_BITS >::operator[] ( size_t  index)
inline

Index into a BitSet, returning a proxy that will allow bit assignment to work.

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::operator^ ( const BitSet< NUM_BITS > &  ar2) const
inline

Operator bitwise XOR...

template<size_t NUM_BITS>
const BitSet& emp::BitSet< NUM_BITS >::operator^= ( const BitSet< NUM_BITS > &  ar2)
inline

Compound operator bitwise XOR...

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::operator| ( const BitSet< NUM_BITS > &  ar2) const
inline

Operator bitwise OR...

template<size_t NUM_BITS>
const BitSet& emp::BitSet< NUM_BITS >::operator|= ( const BitSet< NUM_BITS > &  ar2)
inline

Compound operator bitwise OR...

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::operator~ ( ) const
inline

Operator bitwise NOT...

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::OR ( const BitSet< NUM_BITS > &  set2) const
inline

Perform a Boolean OR with a second BitSet and return the result.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::OR_SELF ( const BitSet< NUM_BITS > &  set2)
inline

Perform a Boolean OR with a second BitSet, store result here, and return this object.

template<size_t NUM_BITS>
int emp::BitSet< NUM_BITS >::PopBit ( )
inline

Return index of first one in sequence (or -1 if no ones); change this position to zero.

template<size_t NUM_BITS>
void emp::BitSet< NUM_BITS >::Print ( std::ostream &  out = std::cout) const
inline

Print all bits to the provided output stream.

template<size_t NUM_BITS>
void emp::BitSet< NUM_BITS >::PrintArray ( std::ostream &  out = std::cout) const
inline

Print all bits from smallest to largest, as if this were an array, not a bit representation.

template<size_t NUM_BITS>
void emp::BitSet< NUM_BITS >::PrintOneIDs ( std::ostream &  out = std::cout,
char  spacer = ' ' 
) const
inline

Print the locations of all one bits, using the provided spacer (default is a single space)

template<size_t NUM_BITS>
void emp::BitSet< NUM_BITS >::Randomize ( Random random,
const double  p1 = 0.5 
)
inline

Set all bits randomly, with a given probability of being a 1.

template<size_t NUM_BITS>
void emp::BitSet< NUM_BITS >::Set ( size_t  index,
bool  value 
)
inline

Set the bit as a specified index.

template<size_t NUM_BITS>
void emp::BitSet< NUM_BITS >::SetAll ( )
inline

Set all bits to one.

template<size_t NUM_BITS>
void emp::BitSet< NUM_BITS >::SetByte ( size_t  index,
uint8_t  value 
)
inline

Set the full byte starting at the bit at the specified index.

template<size_t NUM_BITS>
void emp::BitSet< NUM_BITS >::SetUInt ( size_t  index,
uint32_t  value 
)
inline

Set the 32-bit unsigned int; index in in 32-bit jumps (i.e., this is a field ID not bit id)

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::SHIFT ( const int  shift_size) const
inline

Positive shifts go left and negative go right (0 does nothing); return result.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::SHIFT_SELF ( const int  shift_size)
inline

Positive shifts go left and negative go right; store result here, and return this object.

template<size_t NUM_BITS>
static constexpr size_t emp::BitSet< NUM_BITS >::size ( )
inlinestatic

Function to allow drop-in replacement with std::bitset.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::Toggle ( )
inline

Flip all bits in this BitSet.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::Toggle ( size_t  index)
inline

Flip a single bit.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::Toggle ( size_t  start,
size_t  end 
)
inline

Flips all the bits in a range [start, end)

template<size_t NUM_BITS>
BitSet emp::BitSet< NUM_BITS >::XOR ( const BitSet< NUM_BITS > &  set2) const
inline

Perform a Boolean XOR with a second BitSet and return the result.

template<size_t NUM_BITS>
BitSet& emp::BitSet< NUM_BITS >::XOR_SELF ( const BitSet< NUM_BITS > &  set2)
inline

Perform a Boolean XOR with a second BitSet, store result here, and return this object.

Friends And Related Function Documentation

template<size_t NUM_BITS>
friend class BitProxy
friend

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