Evo C++ Library v0.5.1
|
#include <evo/bit_array.h>
Dynamic bit array container with similar interface to Array and List.
T | Chunk value type for storing bits, must be an unsigned integer type – default: ulong |
TSize | Size integer type, must be unsigned – default: SizeT |
C++11:
Note that this is not a full EvoContainer and has more limited iterators.
Output:
Public Types | |
typedef void | EvoContainerType |
Identify Evo container type. More... | |
typedef IteratorFw< ThisType >::Const | Iter |
Iterator (const) - IteratorFw. More... | |
typedef TSize | Size |
Size integer type. More... | |
typedef BitArraySubsetT< ThisType > | Subset |
Subset type for this bit array type. More... | |
typedef BitArrayT< T, TSize > | ThisType |
This bit array type. More... | |
typedef T | Value |
Chunk value type for bits. More... | |
Public Member Functions | |
BitArrayT () | |
Default constructor sets as null. More... | |
BitArrayT (Size bitsize) | |
Constructor create bit array. More... | |
BitArrayT (const ThisType &src) | |
Copy constructor. More... | |
BitArrayT (const ThisType &src, Size pos, Size count=ALL) | |
Copy from another bit array. More... | |
BitArrayT (const Subset &subset, Size pos=0, Size count=ALL) | |
Copy from subset. More... | |
BitArrayT (std::initializer_list< uint32 > init) | |
Sequence constructor that initializes bits from a list of uint32 values (C++11). More... | |
BitArrayT (ThisType &&src) | |
Move constructor (C++11). More... | |
~BitArrayT () | |
Destructor. More... | |
const ThisType & | asconst () const |
Explicitly use a const reference to this. More... | |
Iter | begin () const |
Get iterator at first item (const). More... | |
Iter | cbegin () const |
Get iterator at first item (const). More... | |
Iter | cend () const |
Get iterator at end (const). More... | |
bool | checkall () const |
Check if all bits are set in bit array (const). More... | |
bool | checkany () const |
Check if any bits are set in bit array (const). More... | |
ThisType & | clear () |
Clear by freeing all values. More... | |
bool | clearbit (Size pos) |
Clear bit at position in bit array. More... | |
Size | clearbits (Size pos=0, Size count=ALL) const |
Clear count bits at position in bit array. More... | |
Size | countbits (bool value=true) const |
Count number of bits set or cleared (const). More... | |
const Value * | data () const |
Get data pointer (const). More... | |
bool | empty () const |
Get whether empty. More... | |
Iter | end () const |
Get iterator at end (const). More... | |
template<class U = uint32> | |
U | extractl (Size pos=0, Size count=ALL) const |
Extract bits from bit array. More... | |
template<class U = uint32> | |
U | extractr (Size pos=0, Size count=ALL) const |
Extract bits from bit array. More... | |
template<class U > | |
bool | format (U &out, int base=fBIN) |
Format bits to stream or string using base. More... | |
bool | getbit (Size pos) const |
Get bit at position in bit array (const). More... | |
ulong | hash (ulong seed=0) const |
Get data hash value for whole bit array. More... | |
Size | load (const char *str, Size size, int base=2) |
Parse and load bits from numeric string. More... | |
bool | null () const |
Get whether null. More... | |
bool | operator!= (const ThisType &data) const |
Inequality operator. More... | |
ThisType & | operator= (ThisType &&src) |
Move assignment operator (C++11). More... | |
ThisType & | operator= (const ThisType &src) |
Assignment operator. More... | |
bool | operator== (const ThisType &data) const |
Equality operator. More... | |
bool | operator[] (Size pos) const |
Get bit at position in bit array (const). More... | |
ThisType & | resize (Size bitsize) |
Resize while preserving existing data (modifier). More... | |
ThisType & | resize_pow2 (Size bitsize) |
Resize as power of 2 while preserving existing data (modifier). More... | |
ThisType & | set () |
Set as null and empty. More... | |
ThisType & | set (const ThisType &src) |
Set as copy of another bit array. More... | |
ThisType & | set (const Subset &src) |
Set as copy of bit array subset. More... | |
bool | setbit (Size pos, bool value=true) |
Set or clear bit at position in bit array. More... | |
Size | setbits (Size pos=0, Size count=ALL, bool value=true) |
Set or clear count bits at position in bit array. More... | |
ThisType & | setempty () |
Set as empty but not null. More... | |
bool | shared () const |
Get whether shared (false). More... | |
ThisType & | shiftl (uint count) |
Shift all bits in bit bit array to the left. More... | |
ThisType & | shiftr (uint count) |
Shift all bits in bit bit array to the right. More... | |
Size | size () const |
Get bit size. More... | |
template<class U > | |
bool | store (Size pos, Size count, U value) |
Stores bits from value in bit array. More... | |
bool | togglebit (Size pos) |
Toggle bit at position in bit array. More... | |
Size | togglebits (Size pos=0, uint count=ALL) |
Toggle count bits at position in bit array. More... | |
ThisType & | unshare () |
Make data unique – no-op. More... | |
Friends | |
template<class > | |
class | BitArraySubsetT |
typedef void EvoContainerType |
Identify Evo container type.
typedef IteratorFw<ThisType>::Const Iter |
Iterator (const) - IteratorFw.
typedef TSize Size |
Size integer type.
typedef BitArraySubsetT<ThisType> Subset |
Subset type for this bit array type.
typedef T Value |
Chunk value type for bits.
|
inline |
Default constructor sets as null.
Constructor create bit array.
bitsize | Bit size to initialize with |
Copy from another bit array.
src | Bit array subset to copy from |
pos | Bit position in src to copy from, 0 for first bit on left, etc |
count | Number of bits to copy from src, ALL for all from pos |
Copy from subset.
subset | Bit array subset to copy from |
pos | Bit position in subset to copy from, 0 for first bit on left, etc |
count | Number of bits to copy from subset, ALL for all from pos |
|
inline |
Destructor.
|
inline |
Sequence constructor that initializes bits from a list of uint32 values (C++11).
init | Initializer list, passed as comma-separated uint32 values in braces { } |
|
inline |
Explicitly use a const reference to this.
|
inline |
|
inline |
|
inline |
|
inline |
Check if all bits are set in bit array (const).
|
inline |
Check if any bits are set in bit array (const).
|
inline |
Clear by freeing all values.
|
inline |
Clear bit at position in bit array.
pos | Bit position to clear, 0 for first bit on left, etc |
pos
out of bounds Clear count bits at position in bit array.
pos | Bit position to clear, 0 for first bit on left, etc |
count | Number of bits to clear from pos, ALL for all from pos |
|
inline |
Count number of bits set or cleared (const).
value | Whether to count bits set, false to count cleared bits (not set) |
|
inline |
Get data pointer (const).
|
inline |
|
inline |
Extract bits from bit array.
111
returned as uint8
: 11100000
U | Return type for extracted bits, must be unsigned (uint, ulong, uint32, etc) – defaults to ulong in C++11 or newer |
pos | Bit position to extract from, 0 for first bit on left, etc |
count | Number of bits to extract, truncated if larger than bitsize or return value |
Extract bits from bit array.
111
returned as uint8
: 00000111
or 7
in decimalcount
larger than bits in return type will be truncated – this should be avoided as it may not be easy to tell how many bits were truncatedcount=9
with return type uint8
then this uses count=8
count
may go out of bit array bounds without truncation – bits from out of bounds are set to 0 and still are right-aligned according to count
U | Return type for extracted bits, must be unsigned (uint, ulong, uint32, etc) – defaults to ulong in C++11 or newer |
pos | Bit position to extract from, 0 for first bit on left, etc |
count | Number of bits to extract, ALL for num bits in return type, truncated if larger than bits in return type |
|
inline |
Format bits to stream or string using base.
8
, or 5 set bits formatted as hex is F8
U | Output string/stream type, deduced from arguments |
out | Output string or stream (or associated Format object) to format to |
base | Base to format as, must be a power of 2 between 2-32 (inclusive), add 100 for lowercase letters, or use enum:
|
|
inline |
Get bit at position in bit array (const).
pos | Bit position to get, 0 for first bit on left, etc |
pos
is out of bounds
|
inline |
Get data hash value for whole bit array.
seed | Seed value for hashing multiple values, 0 if none |
Parse and load bits from numeric string.
str | Pointer to string to load |
size | String length to load |
base | String number base to use: 2 for binary, 8 for octal, 16 for hex – must be a power of 2 in the range 2-32 (inclusive) |
|
inline |
Get whether null.
|
inline |
Inequality operator.
data | Data to compare to |
Move assignment operator (C++11).
src | Source to move |
Assignment operator.
src | Bit array to copy |
|
inline |
Equality operator.
data | Data to compare to |
|
inline |
Resize while preserving existing data (modifier).
bitsize | New bit size to use |
Resize as power of 2 while preserving existing data (modifier).
bitsize | New size to use |
|
inline |
Set as null and empty.
Set as copy of another bit array.
src | Data to copy |
Set as copy of bit array subset.
src | Data to copy, which may reference this same BitArray |
|
inline |
Set or clear bit at position in bit array.
pos | Bit position to set, 0 for first bit on left, etc |
value | Bit value to set, true to set bit, false to clear bit |
pos
out of bounds Set or clear count bits at position in bit array.
pos | Bit position to set, 0 for first bit on left, etc |
count | Number of bits to set from pos, ALL for all from pos |
value | Bit value to set, true to set bits, false to clear bits |
|
inline |
Set as empty but not null.
|
inline |
Get whether shared (false).
|
inline |
Shift all bits in bit bit array to the left.
count | Count to shift |
|
inline |
Shift all bits in bit bit array to the right.
count | Count to shift |
|
inline |
Get bit size.
Stores bits from value in bit array.
00000111
with count=3
would store 111
(3 right-most bits) or 7
in decimalvalue
size, count is capped at that size – only bits from value
are storedU | Value type to store, signed value is treated as unsigned – inferred from value param |
pos | Bit position to store at, 0 for first bit on left, etc |
count | Number of bits to store from value |
value | Value to store (count right-most bits are stored) |
pos
is out of bounds
|
inline |
Toggle bit at position in bit array.
pos | Bit position to toggle, 0 for first bit on left, etc |
pos
out of bounds Toggle count bits at position in bit array.
pos | Bit position to toggle, 0 for first bit on left, etc |
count | Number of bits to toggle from pos, ALL for all from pos |
|
inline |
Make data unique – no-op.
|
friend |