SourcePro® 2023.1 |
SourcePro® API Reference Guide |
Represents a bit vector whose length can be changed at runtime. More...
#include <rw/bitvec.h>
Public Member Functions | |
RWBitVec () | |
RWBitVec (size_t N) | |
RWBitVec (size_t N, bool initVal) | |
RWBitVec (const RWByte *bp, size_t N) | |
RWBitVec (const RWBitVec &v) | |
RWBitVec (RWBitVec &&v) | |
~RWBitVec () | |
void | clearBit (size_t i) |
const RWByte * | data () const |
size_t | firstFalse () const |
size_t | firstTrue () const |
unsigned | hash () const |
bool | isEqual (const RWBitVec &v) const |
size_t | length () const |
bool | operator!= (const RWBitVec &v) const |
bool | operator!= (bool b) const |
RWBitVec & | operator&= (const RWBitVec &v) |
RWBitRef | operator() (size_t i) |
bool | operator() (size_t i) const |
RWBitVec & | operator= (const RWBitVec &v) |
RWBitVec & | operator= (RWBitVec &&v) |
RWBitVec & | operator= (bool b) |
bool | operator== (const RWBitVec &v) const |
bool | operator== (bool b) const |
RWBitRef | operator[] (size_t i) |
bool | operator[] (size_t i) const |
RWBitVec & | operator^= (const RWBitVec &v) |
RWBitVec & | operator|= (const RWBitVec &v) |
std::ostream & | printOn (std::ostream &s) const |
void | resize (size_t N) |
std::istream & | scanFrom (std::istream &s) |
void | setBit (size_t i) |
void | swap (RWBitVec &v) |
bool | testBit (size_t i) const |
Friends | |
RWBitVec | operator! (const RWBitVec &v) |
RWBitVec | operator& (const RWBitVec &v1, const RWBitVec &v2) |
std::ostream & | operator<< (std::ostream &s, const RWBitVec &v) |
std::istream & | operator>> (std::istream &s, RWBitVec &v) |
RWBitVec | operator^ (const RWBitVec &v1, const RWBitVec &v2) |
RWBitVec | operator| (const RWBitVec &v1, const RWBitVec &v2) |
size_t | sum (const RWBitVec &v) |
Related Functions | |
(Note that these are not member functions.) | |
RWvostream & | operator<< (RWvostream &str, const RWBitVec &vec) |
RWFile & | operator<< (RWFile &file, const RWBitVec &vec) |
RWvistream & | operator>> (RWvistream &str, RWBitVec &vec) |
RWFile & | operator>> (RWFile &file, RWBitVec &vec) |
Class RWBitVec is a bit vector whose length can be changed at runtime. Because this requires an extra level of indirection, this makes it slightly less efficient than RWTBitVec, whose lengths are fixed at compile time.
Program output:
|
inline |
Constructs a zero length (null) vector.
RWBitVec::RWBitVec | ( | size_t | N | ) |
Constructs a vector with N bits. The initial value of the bits is undefined.
RWBitVec::RWBitVec | ( | size_t | N, |
bool | initVal | ||
) |
Constructs a vector with N bits, each set to the Boolean value initVal.
RWBitVec::RWBitVec | ( | const RWByte * | bp, |
size_t | N | ||
) |
Constructs a vector with N bits, initialized to the data in the array of bytes pointed to by bp. This array must be at least long enough to contain N bits. The identifier RWByte
is a typedef for an unsigned char
.
RWBitVec::RWBitVec | ( | const RWBitVec & | v | ) |
Copy constructor. Uses value semantics. The constructed vector is a copy of v.
RWBitVec::RWBitVec | ( | RWBitVec && | v | ) |
Move constructor. The constructed vector takes ownership of the data owned by v.
RWBitVec::~RWBitVec | ( | ) |
The destructor. Releases any allocated memory.
|
inline |
Clears (i.e., sets to false
) the bit with index i. The index i must be between 0
and the length of the vector less one. No bounds checking is performed. The following are equivalent, although clearBit(size_t) is slightly smaller and faster than using operator()(size_t):
|
inline |
Returns a const pointer to the raw data of self. Should be used with care.
|
inline |
Returns the index of the first false
bit in self. Returns RW_NPOS if there is no false
bit.
|
inline |
Returns the index of the first true
bit in self. Returns RW_NPOS if there is no true
bit.
unsigned RWBitVec::hash | ( | ) | const |
Returns a value suitable for hashing.
bool RWBitVec::isEqual | ( | const RWBitVec & | v | ) | const |
Returns true
if self and v have the same length and if each bit of self is set to the same value as the corresponding bit in v. Otherwise, returns false
.
|
inline |
Returns the number of bits in the vector.
|
inline |
Returns false
if self and v have the same length and if each bit of self is set to the same value as the corresponding bit in v. Otherwise, returns true
.
|
inline |
Returns false
if every bit of self is set to the boolean value b. Otherwise, returns true
.
Logical assignment. Sets each element of self to the logical AND
of self and the corresponding bit in v. Self and v must have the same number of elements (i.e., be conformal) or an exception of type RWInternalErr is thrown.
|
inline |
Returns a reference to bit i of self. A helper class, RWBitRef, is used. The result can be used as an lvalue. The index i must be between 0
and the length of the vector less one. Bounds checking is performed only if the preprocessor macro RWBOUNDS_CHECK
has been defined before including the header file <rw/bitvec.h>
. If so, and if the index is out of range, then an exception of type RWBoundsErr is thrown.
|
inline |
Returns the boolean value of bit i. The result cannot be used as an lvalue. The index i must be between 0
and the length of the vector less one. Bounds checking is performed only if the preprocessor macro RWBOUNDS_CHECK
has been defined before including the header file <rw/bitvec.h>
. If so, and if the index is out of range, then an exception of type RWBoundsErr is thrown.
Assignment operator. Uses value semantics. Self is a copy of v.
Move assignment. Self takes ownership of the data owned by v.
RWBitVec& RWBitVec::operator= | ( | bool | b | ) |
Assignment operator. Sets every bit in self to the boolean value b.
|
inline |
Returns true
if self and v have the same length and if each bit of self is set to the same value as the corresponding bit in v. Otherwise, returns false
.
bool RWBitVec::operator== | ( | bool | b | ) | const |
Returns true
if every bit of self is set to the boolean value b. Otherwise, returns false
.
|
inline |
Returns a reference to bit i of self. A helper class, RWBitRef, is used. The result can be used as an lvalue. The index i must be between 0
and the length of the vector less one. Bounds checking is performed. If the index is out of range, then an exception of type RWBoundsErr is thrown.
|
inline |
Returns the boolean value of bit i. The result cannot be used as an lvalue. The index i must be between 0
and the length of the vector less one. Bounds checking is performed. If the index is out of range, then an exception of type RWBoundsErr is thrown.
Logical assignment. Sets each element of self to the logical XOR
of self and the corresponding bit in v. Self and v must have the same number of elements (i.e., be conformal) or an exception of type RWInternalErr is thrown.
Logical assignment. Sets each element of self to the logical OR
of self and the corresponding bit in v. Self and v must have the same number of elements (i.e., be conformal) or an exception of type RWInternalErr is thrown.
std::ostream& RWBitVec::printOn | ( | std::ostream & | s | ) | const |
Prints the bit vector on the output stream s. See the example above for a sample of the format.
void RWBitVec::resize | ( | size_t | N | ) |
Resizes the vector to have length N. If this results in a lengthening of the vector, the additional bits are set to false
.
std::istream& RWBitVec::scanFrom | ( | std::istream & | s | ) |
Reads the bit vector from the input stream s. The vector is dynamically resized as necessary. The vector should be in the same format printed by member function printOn(std::ostream&) const.
|
inline |
Sets (i.e., sets to true
) the bit with index i. The index i must be between 0
and size-1
. No bounds checking is performed. The following are equivalent, although setBit(size_t) is slightly smaller and faster than using operator()(size_t):
void RWBitVec::swap | ( | RWBitVec & | v | ) |
Swaps the data owned by self with the data owned by v.
|
inline |
Tests the bit with index i. The index i must be between 0
and size-1
. No bounds checking is performed. The following are equivalent, although testBit(size_t) is slightly smaller and faster than using operator()(size_t):
Unary operator that returns the logical negation of vector v.
Returns a vector that is the logical AND
of the vectors v1 and v2. The two vectors must have the same length or an exception of type RWInternalErr is thrown.
|
friend |
Prints the bit vector v on the output stream s.
|
related |
Saves the RWBitVec vec to a virtual stream.
|
friend |
Reads the bit vector v from the input stream s.
|
related |
Restores an RWBitVec into vec from a virtual stream, replacing the previous contents of vec.
Returns a vector that is the logical XOR
of the vectors v1 and v2. The two vectors must have the same length or an exception of type RWInternalErr is thrown.
Returns a vector that is the logical OR
of the vectors v1 and v2. The two vectors must have the same length or an exception of type RWInternalErr is thrown.
|
friend |
Returns the total number of bits set in the vector v.
Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved. |