CIRCT 22.0.0git
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Protected Attributes | Friends | List of all members
esi::BitVector Class Reference

A lightweight, non-owning bit vector view backed by a byte array span. More...

#include <Values.h>

Inheritance diagram for esi::BitVector:
Inheritance graph
[legend]
Collaboration diagram for esi::BitVector:
Collaboration graph
[legend]

Classes

class  bit_iterator
 Forward iterator for iterating over bits from LSB (index 0) to MSB. More...
 

Public Types

using byte = uint8_t
 

Public Member Functions

 BitVector (std::span< const byte > bytes, std::optional< size_t > width=std::nullopt, uint8_t bitIndex=0)
 Construct from an existing span.
 
 BitVector ()=default
 
 BitVector (const BitVector &other)
 
BitVectoroperator= (const BitVector &other)
 
size_t width () const
 
size_t size () const
 
bool getBit (size_t i) const
 Return the i-th bit (0 = LSB) as boolean.
 
std::span< const bytegetSpan () const
 Return a handle to the underlying span.
 
BitVector operator>> (size_t n) const
 Logical right shift that drops the least-significant n bits by advancing the byte/bit index and reducing width.
 
BitVectoroperator>>= (size_t n)
 
BitVector slice (size_t offset, size_t sliceWidth) const
 Create a new immutable view of a contiguous bit slice [offset, offset+sliceWidth).
 
BitVector lsb (size_t n) const
 Return a view of the N least-significant bits.
 
BitVector msb (size_t n) const
 Return a view of the N most-significant bits.
 
std::string toString (unsigned base=16) const
 
bool operator== (const BitVector &rhs) const
 
bool operator!= (const BitVector &rhs) const
 
bit_iterator begin () const
 Return an iterator to the first bit (LSB).
 
bit_iterator end () const
 Return an iterator past the last bit.
 

Protected Attributes

std::span< const bytedata {}
 
size_t bitWidth = 0
 
uint8_t bitIndex = 0
 

Friends

MutableBitVector operator& (const BitVector &a, const BitVector &b)
 Bitwise AND: creates a new MutableBitVector with the result.
 
MutableBitVector operator| (const BitVector &a, const BitVector &b)
 Bitwise OR: creates a new MutableBitVector with the result.
 
MutableBitVector operator^ (const BitVector &a, const BitVector &b)
 Bitwise XOR: creates a new MutableBitVector with the result.
 

Detailed Description

A lightweight, non-owning bit vector view backed by a byte array span.

BitVector is immutable wrt. modifying the underlying bits, and provides read-only access to bits. It supports bit-level access and returns new views for operations.

Definition at line 42 of file Values.h.

Member Typedef Documentation

◆ byte

using esi::BitVector::byte = uint8_t

Definition at line 44 of file Values.h.

Constructor & Destructor Documentation

◆ BitVector() [1/3]

BitVector::BitVector ( std::span< const byte bytes,
std::optional< size_t >  width = std::nullopt,
uint8_t  bitIndex = 0 
)

Construct from an existing span.

Width defaults to the number of bits in the span (size * 8). The BitVector does not take ownership.

Definition at line 16 of file Values.cpp.

References bitIndex, bitWidth, and data.

◆ BitVector() [2/3]

esi::BitVector::BitVector ( )
default

◆ BitVector() [3/3]

BitVector::BitVector ( const BitVector other)

Definition at line 29 of file Values.cpp.

Member Function Documentation

◆ begin()

bit_iterator esi::BitVector::begin ( ) const
inline

Return an iterator to the first bit (LSB).

Definition at line 171 of file Values.h.

◆ end()

bit_iterator esi::BitVector::end ( ) const
inline

Return an iterator past the last bit.

Definition at line 174 of file Values.h.

References bitWidth.

◆ getBit()

bool BitVector::getBit ( size_t  i) const

◆ getSpan()

std::span< const byte > esi::BitVector::getSpan ( ) const
inline

Return a handle to the underlying span.

Throws if the current bit index is not 0 (since a non-zero bit offset breaks raw byte alignment).

Definition at line 62 of file Values.h.

References bitIndex, and data.

◆ lsb()

BitVector esi::BitVector::lsb ( size_t  n) const
inline

Return a view of the N least-significant bits.

Definition at line 81 of file Values.h.

References slice().

◆ msb()

BitVector esi::BitVector::msb ( size_t  n) const
inline

Return a view of the N most-significant bits.

Definition at line 84 of file Values.h.

References bitWidth, and slice().

◆ operator!=()

bool esi::BitVector::operator!= ( const BitVector rhs) const
inline

Definition at line 93 of file Values.h.

◆ operator=()

BitVector & BitVector::operator= ( const BitVector other)

Definition at line 32 of file Values.cpp.

References bitIndex, bitWidth, and data.

◆ operator==()

bool BitVector::operator== ( const BitVector rhs) const

Definition at line 420 of file Values.cpp.

References bitWidth.

◆ operator>>()

BitVector BitVector::operator>> ( size_t  n) const

Logical right shift that drops the least-significant n bits by advancing the byte/bit index and reducing width.

Returns a new immutable view. Does not modify the underlying storage contents.

Definition at line 50 of file Values.cpp.

References bitIndex, bitWidth, data, and empty.

◆ operator>>=()

BitVector & BitVector::operator>>= ( size_t  n)

Definition at line 78 of file Values.cpp.

◆ size()

size_t esi::BitVector::size ( ) const
inline

◆ slice()

BitVector BitVector::slice ( size_t  offset,
size_t  sliceWidth 
) const

Create a new immutable view of a contiguous bit slice [offset, offset+sliceWidth).

The returned BitVector is a view (not an owning copy) into the same underlying span. Throws if the requested slice exceeds the current width.

Definition at line 83 of file Values.cpp.

References bitIndex, bitWidth, and data.

Referenced by lsb(), and msb().

◆ toString()

std::string BitVector::toString ( unsigned  base = 16) const

Definition at line 362 of file Values.cpp.

References bitWidth, getBit(), toDecimalString(), and toPowerOfTwoString().

Referenced by esi::operator<<().

◆ width()

size_t esi::BitVector::width ( ) const
inline

Friends And Related Symbol Documentation

◆ operator&

MutableBitVector operator& ( const BitVector a,
const BitVector b 
)
friend

Bitwise AND: creates a new MutableBitVector with the result.

◆ operator^

MutableBitVector operator^ ( const BitVector a,
const BitVector b 
)
friend

Bitwise XOR: creates a new MutableBitVector with the result.

◆ operator|

MutableBitVector operator| ( const BitVector a,
const BitVector b 
)
friend

Bitwise OR: creates a new MutableBitVector with the result.

Member Data Documentation

◆ bitIndex

uint8_t esi::BitVector::bitIndex = 0
protected

◆ bitWidth

size_t esi::BitVector::bitWidth = 0
protected

◆ data

std::span<const byte> esi::BitVector::data {}
protected

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