Bits¶
BitMatrix¶
A COL x ROW matrix of bits and provides easy indexing and manipulation.
- Note
This file is part of Empirical, https://github.com/devosoft/Empirical
- Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
- Date
2016-2021
- Note
Status: BETA
-
namespace
emp
If we are in emscripten, make sure to include the header.
-
template<size_t
COLS
, size_tROWS
>
classBitMatrix
- #include <BitMatrix.hpp>
A simple class to manage a COLS x ROWS matrix of bits.
Bits are translated to a bitset with 0 in the upper left and moving through bits from left to right and top to bottom. For example, the indecies in a 3x3 bit matrix would be organized as such:
0 1 2 3 4 5 6 7 8
Public Functions
-
template<size_t
START_POS
, size_tSTEP_POS
, size_tEND_POS
>
constexpr BitSet<COLS * ROWS>Mask
() const
-
BitMatrix
()
-
BitMatrix
(const BitMatrix &in_matrix)
-
~BitMatrix
()
-
constexpr size_t
NumRows
() const How many rows are in this matrix?
-
constexpr size_t
NumCols
() const How many columns are in this matrix?
-
constexpr size_t
GetSize
() const How many total cells are in this matrix?
-
bool
Any
() const
-
bool
None
() const
-
bool
All
() const
-
bool
Get
(size_t col, size_t row) const
-
bool
Get
(size_t id) const
-
void
Set
(size_t col, size_t row, bool val = true)
-
void
Set
(size_t id)
-
void
Unset
(size_t col, size_t row)
-
void
Unset
(size_t id)
-
void
Flip
(size_t col, size_t row)
-
void
Flip
(size_t id)
-
void
SetAll
()
-
void
SetCol
(size_t col)
-
void
SetRow
(size_t row)
-
void
Clear
()
-
void
ClearCol
(size_t col)
-
void
ClearRow
(size_t row)
-
size_t
CountOnes
() const
-
int
FindOne
() const
-
BitMatrix
LeftShift
() const
-
BitMatrix
RightShift
() const
-
BitMatrix
UpShift
() const
-
BitMatrix
DownShift
() const
-
BitMatrix
ULShift
() const
-
BitMatrix
DLShift
() const
-
BitMatrix
URShift
() const
-
BitMatrix
DRShift
() const
-
BitMatrix
GetReach
() const
-
BitMatrix
GetRegion
(size_t start_pos) const
-
BitMatrix
GetRegion
(size_t col, size_t row) const
-
bool
IsConnected
() const
-
bool
Has2x2
() const
-
bool
operator==
(const BitMatrix &in) const
-
bool
operator!=
(const BitMatrix &in) const
-
BitMatrix
operator~
() const
Public Static Functions
-
template<size_t
COL_ID
>
const BitSet<COLS * ROWS> &MaskCol
() Keep only a single column of values, reducing all others to zeros.
-
template<size_t
ROW_ID
>
const BitSet<COLS * ROWS> &MaskRow
() Keep only a single row of values, reducing all others to zeros.
-
size_t
ToCol
(size_t id) Identify which column a specific ID is part of.
-
size_t
ToRow
(size_t id) Identify which row a specific ID is part of.
-
size_t
ToID
(size_t col, size_t row) Identify the ID associated with a specified row and column.
-
template<size_t
-
template<size_t
BitSet¶
A drop-in replacement for std::bitset, with additional bit magic features; aliases BitArray.
- Note
This file is part of Empirical, https://github.com/devosoft/Empirical
- Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
- Date
2016-2021.
- Note
Status: RELEASE
-
namespace
emp
If we are in emscripten, make sure to include the header.
BitSet Utilities¶
A set of simple functions to manipulate bitsets.
- Note
This file is part of Empirical, https://github.com/devosoft/Empirical
- Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
- Date
2016-2020.
- Note
Status: BETA
-
namespace
emp
If we are in emscripten, make sure to include the header.
Functions
-
template<int
NUM_BITS
>
constexpr uint32_tUIntMaskFirst
() Create a series of a specified number of ones (at compile time) in a uint.
-
template<>
constexpr uint32_tUIntMaskFirst
<0>() Create an empty bit mask (all zeros)
-
constexpr size_t
count_bits
(uint64_t val) Count the number of bits in a 64-bit unsigned integer.
-
template<typename
T
>
constexpr size_tfind_bit
(T val) Return the position of the first one bit.
-
template<typename
T
>
size_tpop_bit
(T &val) Return the position of the first one bit AND REMOVE IT.
-
template<typename
TYPE
>
constexpr intCountOnes
(TYPE x) A compile-time bit counter.
-
template<typename
TYPE
>
constexpr TYPEMaskLow
(std::size_t num_bits) Quick bit-mask generator for low bits.
Variables
-
constexpr size_t
ByteCount
[256] = {0, 1, 1, 2, 1, 2, 2, 3, 1, 2, 2, 3, 2, 3, 3, 4, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 1, 2, 2, 3, 2, 3, 3, 4, 2, 3, 3, 4, 3, 4, 4, 5, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 2, 3, 3, 4, 3, 4, 4, 5, 3, 4, 4, 5, 4, 5, 5, 6, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 3, 4, 4, 5, 4, 5, 5, 6, 4, 5, 5, 6, 5, 6, 6, 7, 4, 5, 5, 6, 5, 6, 6, 7, 5, 6, 6, 7, 6, 7, 7, 8} How many bits are set to one in each possible byte?
-
template<int
BitVector¶
A drop-in replacement for std::vector<bool>, with additional bitwise logic features.
- Note
This file is part of Empirical, https://github.com/devosoft/Empirical
- Copyright
Copyright (C) Michigan State University, MIT Software license; see doc/LICENSE.md
- Date
2016-2021.
- Note
Status: RELEASE
- Note
Compile with -O3 and -msse4.2 for fast bit counting.
- Note
This class is 15-20% slower than emp::BitSet, but more flexible & run-time configurable.
-
template<>
structstd
::
hash
<emp::BitVector> - #include <BitVector.hpp>
Hash function to allow BitVector to be used with maps and sets (must be in std).
-
namespace
emp
If we are in emscripten, make sure to include the header.
-
class
BitVector
- #include <BitVector.hpp>
A drop-in replacement for std::vector<bool>, but with extra bitwise logic features.
This class stores an arbirary number of bits in a set of “fields” (typically 32 bits or 64 bits per field, depending on which should be faster.) Individual bits can be extracted, -or- bitwise logic (including more complex bit magic) can be used on the groups of bits.
Public Functions
-
BitVector
(size_t in_num_bits = 0, bool init_val = false) Build a new BitVector with specified bit count (default 0) and initialization (default 0)
-
template<typename
T
, typename std::enable_if<std::is_arithmetic<T>::value, int>::type = 0>BitVector
(T in_num_bits) Anything not otherwise defined for first argument, convert to size_t.
-
BitVector
(const BitVector &in) Copy constructor of existing bit field.
-
BitVector
(BitVector &&in) Move constructor of existing bit field.
-
template<size_t
NUM_BITS
>BitVector
(const std::bitset<NUM_BITS> &bitset) Constructor to generate a BitVector from a std::bitset.
-
BitVector
(const std::string &bitstring) Constructor to generate a BitVector from a string of ‘0’s and ‘1’s.
-
BitVector
(const char *bitstring) Constructor to generate a BitVector from a literal string of ‘0’s and ‘1’s.
-
BitVector
(size_t in_num_bits, Random &random) Constructor to generate a random BitVector (with equal prob of 0 or 1).
-
BitVector
(size_t in_num_bits, Random &random, const double p1) Constructor to generate a random BitVector with provided prob of 1’s.
-
BitVector
(size_t in_num_bits, Random &random, const size_t target_ones) Constructor to generate a random BitVector with provided number of 1’s.
-
BitVector
(size_t in_num_bits, Random &random, const int target_ones) Constructor to generate a random BitVector with provided number of 1’s.
-
BitVector
(const BitVector &in, size_t new_size) Copy, but with a resize.
-
~BitVector
() Destructor.
-
template<size_t
NUM_BITS
>
BitVector &operator=
(const std::bitset<NUM_BITS> &bitset) Assignment operator from a std::bitset.
-
BitVector &
operator=
(const std::string &bitstring) Assignment operator from a string of ‘0’s and ‘1’s.
-
BitVector &
operator=
(const char *bitstring) Assignment operator from a literal string of ‘0’s and ‘1’s.
-
BitVector &
Import
(const BitVector &from_bv, const size_t from_bit = 0) Assignment from another BitVector without changing size.
Assign from a BitVector of a different size.
-
BitVector
Export
(size_t out_size, size_t start_bit = 0) const Convert to a BitVector of a different size.
Convert to a Bitset of a different size.
-
bool
OK
() const
-
size_t
GetSize
() const How many bits do we currently have?
-
size_t
GetNumBytes
() const How many bytes are in this BitVector? (includes empty field space)
-
double
GetNumStates
() const How many distinct values could be held in this BitVector?
-
bool
Get
(size_t index) const Retrive the bit value from the specified index.
-
bool
Has
(size_t index) const A safe version of Get() for indexing out of range. Useful for representing collections.
-
BitVector &
Set
(size_t index, bool value = true) Update the bit value at the specified index.
-
BitVector &
SetAll
() Set all bits to 1.
-
BitVector &
SetRange
(size_t start, size_t stop) Set a range of bits to one: [start, stop)
-
BitVector &
Clear
() Set all bits to 0.
-
BitVector &
Clear
(size_t index) Set specific bit to 0.
-
BitVector &
Clear
(const size_t start, const size_t stop) Set bits to 0 in the range [start, stop)
-
bool
operator[]
(size_t index) const Const index operator return the bit at the specified position.
-
BitProxy<BitVector>
operator[]
(size_t index) Index operator return a proxy to the bit at the specified position so it can be an lvalue.
-
BitVector &
Toggle
() Change every bit in the sequence.
-
BitVector &
Toggle
(size_t index) Change a specified bit to the opposite value.
-
BitVector &
Toggle
(size_t start, size_t stop) Flips all the bits in a range [start, end)
-
bool
Any
() const Return true if ANY bits are set to 1, otherwise return false.
-
bool
None
() const Return true if NO bits are set to 1, otherwise return false.
-
bool
All
() const Return true if ALL bits are set to 1, otherwise return false.
-
BitVector &
Randomize
(Random &random) Set all bits randomly, with a 50% probability of being a 0 or 1.
-
template<Random::Prob
P
>
BitVector &RandomizeP
(Random &random, const size_t start_pos = 0, size_t stop_pos = MAX_BITS) Set all bits randomly, with probability specified at compile time.
-
BitVector &
Randomize
(Random &random, const double p, const size_t start_pos = 0, size_t stop_pos = MAX_BITS) Set all bits randomly, with a given probability of being a one.
Set all bits randomly, with a given probability of being on.
-
BitVector &
ChooseRandom
(Random &random, const int target_ones, const size_t start_pos = 0, size_t stop_pos = MAX_BITS) Set all bits randomly, with a given number of ones.
Set all bits randomly, with a given number of them being on.
-
BitVector &
FlipRandom
(Random &random, const double p, const size_t start_pos = 0, size_t stop_pos = MAX_BITS) Flip random bits with a given probability.
-
BitVector &
SetRandom
(Random &random, const double p, const size_t start_pos = 0, size_t stop_pos = MAX_BITS) Set random bits with a given probability (does not check if already set.)
-
BitVector &
ClearRandom
(Random &random, const double p, const size_t start_pos = 0, size_t stop_pos = MAX_BITS) Unset random bits with a given probability (does not check if already zero.)
-
BitVector &
FlipRandomCount
(Random &random, const size_t target_bits) Flip a specified number of random bits.
-
BitVector &
SetRandomCount
(Random &random, const size_t target_bits) Set a specified number of random bits (does not check if already set.)
-
BitVector &
ClearRandomCount
(Random &random, const size_t target_bits) Unset a specified number of random bits (does not check if already zero.)
-
bool
operator==
(const BitVector &in) const Test if two bit vectors are identical.
-
bool
operator!=
(const BitVector &in) const
-
bool
operator<
(const BitVector &in) const Compare the would-be numerical values of two bit vectors.
-
bool
operator>
(const BitVector &in) const
-
bool
operator<=
(const BitVector &in) const
-
bool
operator>=
(const BitVector &in) const
-
template<typename
T
>operator emp::vector<T>
() Automatically convert BitVector to other vector types.
-
operator bool
() const Casting a bit array to bool identifies if ANY bits are set to 1.
-
uint8_t
GetByte
(size_t index) const Retrive the byte at the specified byte index.
-
std::span<const std::byte>
GetBytes
() const Get a read-only view into the internal array used by BitVector.
- Return
Read-only span of BitVector’s bytes.
-
emp::Ptr<const unsigned char>
RawBytes
() const Get a read-only pointer to the internal array used by BitVector. (note that bits are NOT in order at the byte level!)
- Return
Read-only pointer to BitVector’s bytes.
-
void
SetByte
(size_t index, uint8_t value) Update the byte at the specified byte index.
-
double
GetValue
() const Get the overall value of this BitVector, using a uint encoding, but including all bits and returning the value as a double.
Get the overall value of this BitSet, using a uint encoding, but including all bits and returning the value as a double.
-
template<typename
T
>
TGetValueAtIndex
(const size_t index) const Get specified type at a given index (in steps of that type size)
-
uint8_t
GetUInt8
(size_t index) const
-
uint16_t
GetUInt16
(size_t index) const
-
uint32_t
GetUInt32
(size_t index) const
-
uint64_t
GetUInt64
(size_t index) const
-
uint32_t
GetUInt
(size_t index) const
-
template<typename
T
>
voidSetValueAtIndex
(const size_t index, T value) Set specified type at a given index (in steps of that type size)
-
void
SetUInt8
(const size_t index, uint8_t value) Update the 8-bit uint at the specified uint index.
-
void
SetUInt16
(const size_t index, uint16_t value) Update the 16-bit uint at the specified uint index.
-
void
SetUInt32
(const size_t index, uint32_t value) Update the 32-bit uint at the specified uint index.
-
void
SetUInt64
(const size_t index, uint64_t value) Update the 64-bit uint at the specified uint index.
-
void
SetUInt
(const size_t index, uint32_t value) By default, update the 32-bit uint at the specified uint index.
-
template<typename
T
>
TGetValueAtBit
(const size_t index) const Get specified type starting at a given BIT position.
Get the specified type starting from a given BIT position.
-
uint8_t
GetUInt8AtBit
(size_t index) const
-
uint16_t
GetUInt16AtBit
(size_t index) const
-
uint32_t
GetUInt32AtBit
(size_t index) const
-
uint64_t
GetUInt64AtBit
(size_t index) const
-
uint32_t
GetUIntAtBit
(size_t index) const
-
template<typename
T
>
voidSetValueAtBit
(const size_t index, T value) Set the specified type starting from a given BIT position.
-
void
SetUInt8AtBit
(const size_t index, uint8_t value) Update the 8-bit uint at the specified uint index.
-
void
SetUInt16AtBit
(const size_t index, uint16_t value) Update the 16-bit uint at the specified uint index.
-
void
SetUInt32AtBit
(const size_t index, uint32_t value) Update the 32-bit uint at the specified uint index.
-
void
SetUInt64AtBit
(const size_t index, uint64_t value) Update the 64-bit uint at the specified uint index.
-
void
SetUIntAtBit
(const size_t index, uint32_t value) By default, update the 32-bit uint at the specified uint index.
-
std::size_t
Hash
(size_t start_field = 0) const A simple hash function for bit vectors.
-
size_t
CountOnes
() const Count the number of ones in the BitVector.
-
size_t
CountOnes_Sparse
() const Faster counting of ones for very sparse bit vectors.
-
size_t
CountZeros
() const Count the number of zeros in the BitVector.
-
bool
PopBack
() Pop the last bit in the vector.
- Return
value of the popped bit.
-
void
PushBack
(const bool bit = true, const size_t num = 1) Push given bit(s) onto the back of a vector.
- Parameters
bit
: value of bit to be pushed.num
: number of bits to be pushed.
-
void
Insert
(const size_t index, const bool val = true, const size_t num = 1) Insert bit(s) into any index of vector using bit magic. Blog post on implementation reasoning: https://devolab.org/?p=2249
Insert bit(s) into any index of vector using bit magic. Blog post on implementation reasoning:
https://devolab.org/?p=2249- Parameters
index
: location to insert bit(s).val
: value of bit(s) to insert.num
: number of bits to insert, default 1.
- Parameters
index
: location to insert bit(s).val
: value of bit(s) to insert (default true)num
: number of bits to insert, default 1.
-
void
Delete
(const size_t index, const size_t num = 1) Delete bits from any index in a vector. TODO: consider a bit magic approach here.
Delete bits from any index in a vector.
- Parameters
index
: location to delete bit(s).num
: number of bits to delete, default 1.
- Parameters
index
: location to delete bit(s).num
: number of bits to delete, default 1.
-
int
FindOne
() const Return the position of the first one; return -1 if no ones in vector.
-
int
FindBit
() const Deprecated: Return the position of the first one; return -1 if no ones in vector.
-
int
FindOne
(const size_t start_pos) const Return the position of the first one after start_pos; return -1 if no ones in vector. You can loop through all 1-bit positions of a BitVector “bv” with:
for (int pos = bv.FindOne(); pos >= 0; pos = bv.FindOne(pos+1)) { … }
-
int
FindBit
(const size_t start_pos) const Deprecated version of FindOne().
-
int
FindMaxOne
() const Find the most-significant set-bit.
-
int
PopOne
() Return the position of the first one and change it to a zero. Return -1 if no ones.
-
int
PopBit
() Deprecated version of PopOne().
-
size_t
LongestSegmentOnes
() const Find the length of the longest continuous series of ones.
-
bool
HasOverlap
(const BitVector &in) const Return true if any ones are in common with another BitVector.
-
char
GetAsChar
(size_t id) const Convert a specified bit to a character.
-
std::string
ToString
() const Convert this BitVector to a vector string [index 0 on left].
Convert this BitVector to a vector string [0 index on left].
-
std::string
ToBinaryString
() const Convert this BitVector to a numerical string [index 0 on right].
Convert this BitVector to a numerical string [0 index on right].
-
std::string
ToIDString
(const std::string &spacer = " ") const Convert this BitVector to a series of IDs.
-
std::string
ToRangeString
(const std::string &spacer = ",", const std::string &ranger = "-") const Convert this BitVector to a series of IDs with ranges condensed.
-
void
Print
(std::ostream &out = std::cout) const Regular print function (from least significant bit to most)
-
void
PrintBinary
(std::ostream &out = std::cout) const Numerical print function (from most significant bit to least)
-
void
PrintFields
(std::ostream &out = std::cout, const std::string &spacer = " ") const Print a space between each field (or other provided spacer)
-
void
PrintDebug
(std::ostream &out = std::cout) const Print out details about the internals of the BitVector.
Print a space between each field (or other provided spacer)
-
void
PrintOneIDs
(std::ostream &out = std::cout, const std::string &spacer = " ") const Print the positions of all one bits, spaces are the default separator.
-
void
PrintAsRange
(std::ostream &out = std::cout, const std::string &spacer = ",", const std::string &ranger = "-") const Print the ones in a range format. E.g., 2-5,7,10-15.
-
BitVector &
NOT_SELF
() Perform a Boolean NOT with this BitVector, store result here, and return this object.
-
BitVector &
AND_SELF
(const BitVector &bv2) Perform a Boolean AND with this BitVector, store result here, and return this object.
-
BitVector &
OR_SELF
(const BitVector &bv2) Perform a Boolean OR with this BitVector, store result here, and return this object.
-
BitVector &
NAND_SELF
(const BitVector &bv2) Perform a Boolean NAND with this BitVector, store result here, and return this object.
-
BitVector &
NOR_SELF
(const BitVector &bv2) Perform a Boolean NOR with this BitVector, store result here, and return this object.
-
BitVector &
XOR_SELF
(const BitVector &bv2) Perform a Boolean XOR with this BitVector, store result here, and return this object.
-
BitVector &
EQU_SELF
(const BitVector &bv2) Perform a Boolean EQU with this BitVector, store result here, and return this object.
-
BitVector
AND
(const BitVector &bv2) const Perform a Boolean AND on this BitVector and return the result.
-
BitVector
OR
(const BitVector &bv2) const Perform a Boolean OR on this BitVector and return the result.
-
BitVector
NAND
(const BitVector &bv2) const Perform a Boolean NAND on this BitVector and return the result.
-
BitVector
NOR
(const BitVector &bv2) const Perform a Boolean NOR on this BitVector and return the result.
-
BitVector
XOR
(const BitVector &bv2) const Perform a Boolean XOR on this BitVector and return the result.
-
BitVector
EQU
(const BitVector &bv2) const Perform a Boolean EQU on this BitVector and return the result.
-
BitVector
SHIFT
(const int shift_size) const Positive shifts go left and negative go right (0 does nothing); return result.
-
BitVector &
SHIFT_SELF
(const int shift_size) Positive shifts go left and negative go right; store result here, and return this object.
-
BitVector &
REVERSE_SELF
() Reverse the order of bits in the bitset.
-
BitVector
REVERSE
() const Reverse order of bits in the bitset.
-
BitVector
ROTATE
(const int rotate_size) const Positive rotates go left and negative rotates go left (0 does nothing); return result.
-
BitVector &
ROTATE_SELF
(const int rotate_size) Positive rotates go right and negative rotates go left (0 does nothing); store result here, and return this object.
-
template<size_t
shift_size_raw
>
BitVector &ROTL_SELF
() Helper: call ROTATE with negative number instead.
-
template<size_t
shift_size_raw
>
BitVector &ROTR_SELF
() Helper for calling ROTATE with positive number.
-
BitVector
ADD
(const BitVector &set2) const Addition of two BitVectors. Wraps if it overflows. Returns result.
Addition of two Bitsets. Wraps if it overflows. Returns result.
-
BitVector &
ADD_SELF
(const BitVector &set2) Addition of two BitVectors. Wraps if it overflows. Returns this object.
Addition of two Bitsets. Wraps if it overflows. Returns this object.
-
BitVector
SUB
(const BitVector &set2) const Subtraction of two BitVectors. Wraps around if it underflows. Returns result.
Subtraction of two Bitsets. Wraps around if it underflows. Returns result.
-
BitVector &
SUB_SELF
(const BitVector &set2) Subtraction of two BitVectors. Wraps if it underflows. Returns this object.
Subtraction of two Bitsets. Wraps if it underflows. Returns this object.
-
BitVector
operator~
() const Operator bitwise NOT…
-
BitVector
operator<<
(const size_t shift_size) const Operator shift left…
-
BitVector
operator>>
(const size_t shift_size) const Operator shift right…
-
BitVector &
operator<<=
(const size_t shift_size) Compound operator for shift left…
-
BitVector &
operator>>=
(const size_t shift_size) Compound operator for shift right…
-
size_t
size
() const
-
void
resize
(std::size_t new_size)
-
bool
all
() const
-
bool
any
() const
-
bool
none
() const
-
size_t
count
() const
-
BitVector &
flip
()
-
BitVector &
flip
(size_t pos)
-
BitVector &
flip
(size_t start, size_t end)
-
void
reset
()
-
void
reset
(size_t id)
-
void
set
()
-
void
set
(size_t id)
-
bool
test
(size_t index) const
Private Types
-
using
field_t
= size_t
Private Functions
-
size_t
NumEndBits
() const Num bits used in partial field at the end; 0 if perfect fit.
-
size_t
EndGap
() const How many EXTRA bits are leftover in the gap at the end?
-
field_t
EndMask
() const A mask to cut off all of the final bits.
-
size_t
NumFields
() const How many feilds do we need for the current set of bits?
-
size_t
LastField
() const What is the ID of the last occupied field?
-
size_t
NumBytes
() const How many bytes are used for the current set of bits? (rounded up!)
-
size_t
TotalBytes
() const How many bytes are allocated? (rounded up!)
-
void
RawCopy
(const size_t from_start, const size_t from_stop, const size_t to)
-
void
ClearExcessBits
()
-
void
ShiftLeft
(const size_t shift_size)
-
void
ShiftRight
(const size_t shift_size)
-
void
RotateLeft
(const size_t shift_size_raw) Helper: call ROTATE with negative number instead.
Helper: call ROTATE with negative number.
-
void
RotateRight
(const size_t shift_size_raw) Helper for calling ROTATE with positive number.
Private Members
-
size_t
num_bits
Total number of bits are we using.
Private Static Functions
-
constexpr size_t
FieldID
(const size_t index)
-
constexpr size_t
FieldPos
(const size_t index)
-
constexpr size_t
Byte2Field
(const size_t index)
-
constexpr size_t
Byte2FieldPos
(const size_t index)
Private Static Attributes
-
constexpr size_t
FIELD_BITS
= sizeof(field_t) * 8 Number of bits in a field.
-
constexpr size_t
MAX_BITS
= (size_t)-1 Value larger than any bit ID.
-
constexpr size_t
FIELD_LOG2
= emp::Log2(FIELD_BITS)
-
constexpr field_t
FIELD_LOG2_MASK
= MaskLow<field_t>(FIELD_LOG2)
-
-
class
-
namespace
std
For hashing BitArrays.
-
template<> BitVector >
- #include <BitVector.hpp>
Hash function to allow BitVector to be used with maps and sets (must be in std).
-