MT Core (C++)
Core library for replacing C++ standard in project usage
|
Represents a bitset with dynamically allocated memory (using an mtcore allocator) Allows operating on an arbitrary number of bits. More...
#include <bitset.hpp>
Classes | |
struct | BitsetAccess |
Helper for accessing a bitset position (including for setting bits) More... | |
struct | SetBitIter |
Simple bit set iterator that uses next() iteration to return the indices of all set bits. More... | |
Public Member Functions | |
Result< void, AllocationError > | init (mtcore::Allocator &allocator, const size_t total) |
Initializes a bitset to have a total number of bits All bits will be set to zero. | |
Result< void, BitStrInitError > | init (mtcore::Allocator &allocator, const Slice< const char > binaryStr) |
Initializes a bitset from a binary string of 1's and 0's. | |
Result< void, BitStrInitError > | init (mtcore::Allocator &allocator, const size_t total, const Slice< const char > binaryStr) |
Initializes a bitset of a given size from a string Any bits not set by the string will be zero. | |
void | deinit (mtcore::Allocator &allocator) |
Deinitialies a bitset. | |
BitsetAccess | operator[] (const size_t index) |
Access an individual bit at a specific position. | |
bool | operator[] (const size_t index) const |
Access an individual bit at a specific position. | |
size_t | size () const |
Gets the size of the bitset. | |
bool | at (const size_t pos) const |
Reads a bit at a specific position. | |
Result< Bitset, AllocationError > | clone (mtcore::Allocator &allocator) |
Clones a bitset using a specific allocator. | |
Result< Bitset, AllocationError > | clone (mtcore::Allocator &allocator, const size_t newLen) |
Clones and resizes a bitset using a specific allocator. | |
Result< void, AllocationError > | resize (Allocator &alloc, const size_t newLen, const bool newVal=false) |
Bitset & | set (const size_t pos, const bool val) |
Sets a bit at a position to a specific value. | |
Bitset & | toggle (const size_t pos) |
Toggles a bit at a specific position. | |
Optional< size_t > | first_set () const |
Returns the position of the first set bit (if one is set) Otherwise, returns a null Optional. | |
size_t | pop_count () const |
Counts the number of set bits in the bitset. | |
SetBitIter | set_bits () const |
Iterates over the indices of all set bits in the bitset. | |
Bitset & | operator&= (const Bitset &other) |
Bitset & | operator|= (const Bitset &other) |
Bitset & | operator^= (const Bitset &other) |
void | set_all (const bool value) |
Sets all bits to a specific value. | |
Bitset & | operator<<= (const size_t amount) |
Bitset & | operator>>= (const size_t amount) |
Public Attributes | |
Slice< u64 > | bits |
size_t | len = 0 |
Represents a bitset with dynamically allocated memory (using an mtcore allocator) Allows operating on an arbitrary number of bits.
Definition at line 46 of file bitset.hpp.
|
inlinenodiscard |
Reads a bit at a specific position.
pos | Bit index to read |
Definition at line 179 of file bitset.hpp.
|
inline |
Clones a bitset using a specific allocator.
allocator | Allocator to use for cloning |
Definition at line 193 of file bitset.hpp.
|
inline |
Clones and resizes a bitset using a specific allocator.
allocator | Allocator to use for cloning |
newLen | New length for the clone |
Definition at line 204 of file bitset.hpp.
|
inline |
Deinitialies a bitset.
allocator | Allocator to use for deinitialization |
Definition at line 122 of file bitset.hpp.
|
inlinenodiscard |
Returns the position of the first set bit (if one is set) Otherwise, returns a null Optional.
Definition at line 293 of file bitset.hpp.
|
inlinenodiscard |
Initializes a bitset to have a total number of bits All bits will be set to zero.
allocator | Allocator to use for memory allocation |
total | Number of bits to use |
Definition at line 56 of file bitset.hpp.
|
inline |
Initializes a bitset of a given size from a string Any bits not set by the string will be zero.
allocator | Allocator to use for memory allocation |
total | Number of bits to use |
binaryStr | Binary string to use for initializing bits |
Definition at line 88 of file bitset.hpp.
|
inline |
Initializes a bitset from a binary string of 1's and 0's.
allocator | Allocator to use for memory allocation |
binaryStr | Binary string to use for initializing bits |
Definition at line 76 of file bitset.hpp.
|
inline |
Definition at line 398 of file bitset.hpp.
|
inline |
Definition at line 434 of file bitset.hpp.
|
inlinenodiscard |
Access an individual bit at a specific position.
index | Bit index to access |
Definition at line 154 of file bitset.hpp.
|
inlinenodiscard |
Access an individual bit at a specific position.
index | Bit index to access |
Definition at line 165 of file bitset.hpp.
|
inlinenodiscard |
Counts the number of set bits in the bitset.
Definition at line 307 of file bitset.hpp.
|
inline |
Definition at line 217 of file bitset.hpp.
|
inline |
Sets a bit at a position to a specific value.
pos | Bit index to set |
val | Bit value to set to |
Definition at line 257 of file bitset.hpp.
|
inline |
Sets all bits to a specific value.
value | to set to |
Definition at line 383 of file bitset.hpp.
|
inlinenodiscard |
Iterates over the indices of all set bits in the bitset.
Definition at line 346 of file bitset.hpp.
|
inlinenodiscard |
Gets the size of the bitset.
pos | Bit index to read |
Definition at line 172 of file bitset.hpp.
|
inline |
Toggles a bit at a specific position.
pos | Bit index to toggle |
Definition at line 278 of file bitset.hpp.
Definition at line 47 of file bitset.hpp.
size_t mtcore::Bitset::len = 0 |
Definition at line 48 of file bitset.hpp.