36class MutableBitVector;
49 std::optional<size_t>
width = std::nullopt, uint8_t
bitIndex = 0);
58 bool getBit(
size_t i)
const;
64 throw std::runtime_error(
"Cannot get data span with non-zero bit index");
86 throw std::invalid_argument(
"msb width exceeds bit width");
90 std::string
toString(
unsigned base = 16)
const;
123 throw std::out_of_range(
"bit_iterator dereference out of range");
147 return !(*
this == other);
162 return !(*
this == sent);
192 std::optional<size_t>
width = std::nullopt);
213 void setBit(
size_t i,
bool v);
253 Int(int64_t v,
unsigned width = 64);
254 operator int64_t()
const {
return toI64(); }
255 operator int32_t()
const {
return toInt<int32_t>(); }
256 operator int16_t()
const {
return toInt<int16_t>(); }
257 operator int8_t()
const {
return toInt<int8_t>(); }
260 template <
typename T>
262 static_assert(std::is_integral<T>::value && std::is_signed<T>::value,
263 "T must be a signed integral type");
265 fits(v,
sizeof(T) * 8);
266 return static_cast<T
>(v);
271 int64_t
toI64()
const;
274 static void fits(int64_t v,
unsigned n);
283 operator uint64_t()
const {
return toUI64(); }
284 operator uint32_t()
const {
return toUInt<uint32_t>(); }
285 operator uint16_t()
const {
return toUInt<uint16_t>(); }
286 operator uint8_t()
const {
return toUInt<uint8_t>(); }
291 static void fits(uint64_t v,
unsigned n);
293 template <
typename T>
295 static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value,
296 "T must be an unsigned integral type");
298 fits(v,
sizeof(T) * 8);
299 return static_cast<T
>(v);
307inline constexpr bool std::ranges::enable_borrowed_range<esi::BitVector> =
true;
311 std::ranges::enable_borrowed_range<esi::MutableBitVector> =
true;
Forward iterator for iterating over bits from LSB (index 0) to MSB.
std::forward_iterator_tag iterator_category
bit_iterator & operator++()
Pre-increment: move to next bit.
std::ptrdiff_t difference_type
bool operator!=(std::default_sentinel_t sent) const
Sentinel-compatible inequality.
bool operator<(const bit_iterator &other) const
Less-than comparison (for ranges support).
bool operator==(const bit_iterator &other) const
Equality comparison.
bit_iterator()=default
Default constructor.
const BitVector * bitVector
bool operator==(std::default_sentinel_t) const
Sentinel-compatible equality (for ranges support).
bit_iterator(const BitVector *bv, size_t pos=0)
Construct an iterator at the given bit position.
bit_iterator operator++(int)
Post-increment: move to next bit.
bool operator!=(const bit_iterator &other) const
Inequality comparison.
bool operator*() const
Dereference: returns the bit value at the current position.
A lightweight, non-owning bit vector view backed by a byte array span.
friend MutableBitVector operator^(const BitVector &a, const BitVector &b)
Bitwise XOR: creates a new MutableBitVector with the result.
friend MutableBitVector operator&(const BitVector &a, const BitVector &b)
Bitwise AND: creates a new MutableBitVector with the result.
BitVector msb(size_t n) const
Return a view of the N most-significant bits.
BitVector slice(size_t offset, size_t sliceWidth) const
Create a new immutable view of a contiguous bit slice [offset, offset+sliceWidth).
BitVector & operator=(const BitVector &other)
bool getBit(size_t i) const
Return the i-th bit (0 = LSB) as boolean.
BitVector lsb(size_t n) const
Return a view of the N least-significant bits.
std::string toString(unsigned base=16) const
bit_iterator begin() const
Return an iterator to the first bit (LSB).
bool operator!=(const BitVector &rhs) const
std::span< const byte > data
BitVector & operator>>=(size_t n)
BitVector operator>>(size_t n) const
Logical right shift that drops the least-significant n bits by advancing the byte/bit index and reduc...
bool operator==(const BitVector &rhs) const
bit_iterator end() const
Return an iterator past the last bit.
std::span< const byte > getSpan() const
Return a handle to the underlying span.
friend MutableBitVector operator|(const BitVector &a, const BitVector &b)
Bitwise OR: creates a new MutableBitVector with the result.
static void fits(int64_t v, unsigned n)
A mutable bit vector that owns its underlying storage.
MutableBitVector & operator|=(const MutableBitVector &other)
MutableBitVector & operator>>=(size_t n)
In-place logical right shift that drops the least-significant n bits.
std::vector< uint8_t > takeStorage()
Return and transfer ownership of the underlying storage.
MutableBitVector & operator<<=(size_t n)
In-place logical left shift shifts in n zero bits at LSB, shifting existing bits upward.
MutableBitVector operator~() const
std::span< const byte > getSpan() const
Return a handle to the underlying span (always aligned since bitIndex=0).
MutableBitVector & operator&=(const MutableBitVector &other)
MutableBitVector()=default
std::vector< byte > owner
void setBit(size_t i, bool v)
Set the i-th bit.
MutableBitVector & operator=(const MutableBitVector &other)
MutableBitVector & operator^=(const MutableBitVector &other)
static void fits(uint64_t v, unsigned n)
std::ostream & operator<<(std::ostream &os, const BitVector &bv)