Elm  2
ELM is a library providing generic data structures, OS-independent interface, plugins and XML.
BitVector Class Reference

#include <elm/util/BitVector.h>

Classes

class  Iter
 
class  OneIterator
 
class  Ref
 
class  ZeroIterator
 

Public Member Functions

 BitVector (void)
 
 BitVector (int size, bool set=false)
 
 BitVector (const BitVector &vec)
 
 BitVector (const BitVector &vec, int new_size)
 
 ~BitVector (void)
 
int size (void) const
 
bool bit (int i) const
 
bool isEmpty (void) const
 
bool includes (const BitVector &vec) const
 
bool includesStrictly (const BitVector &vec) const
 
bool equals (const BitVector &vec) const
 
int countBits (void) const
 
void resize (int new_size)
 
bool meets (const BitVector &bv)
 
void set (int index) const
 
void set (int index, bool value) const
 
void clear (int index) const
 
void copy (const BitVector &bits) const
 
void clear (void)
 
void set (void)
 
void applyNot (void)
 
void applyOr (const BitVector &vec)
 
void applyAnd (const BitVector &vec)
 
void applyReset (const BitVector &vec)
 
BitVector makeNot (void) const
 
BitVector makeOr (const BitVector &vec) const
 
BitVector makeAnd (const BitVector &vec) const
 
BitVector makeReset (const BitVector &vec) const
 
void print (io::Output &out) const
 
int countOnes (void) const
 
int countZeroes (void) const
 
OneIterator begin () const
 
OneIterator end () const
 
 operator bool (void) const
 
bool operator[] (int index) const
 
Ref operator[] (int i)
 
BitVector operator~ (void) const
 
BitVector operator| (const BitVector &vec) const
 
BitVector operator& (const BitVector &vec) const
 
BitVector operator+ (const BitVector &vec) const
 
BitVector operator- (const BitVector &vec) const
 
BitVectoroperator= (const BitVector &vec)
 
BitVectoroperator|= (const BitVector &vec)
 
BitVectoroperator&= (const BitVector &vec)
 
BitVectoroperator+= (const BitVector &vec)
 
BitVectoroperator-= (const BitVector &vec)
 
bool operator== (const BitVector &vec) const
 
bool operator!= (const BitVector &vec) const
 
bool operator< (const BitVector &vec) const
 
bool operator<= (const BitVector &vec) const
 
bool operator> (const BitVector &vec) const
 
bool operator>= (const BitVector &vec) const
 
t::size __size (void) const
 

Detailed Description

This class provides facilities for managing vector of bits in an optimized way.

Notice that vector is represented as a contiguous block of memory. This bit vector representation is clearly not performant for sparse vectors.

Constructor & Destructor Documentation

◆ BitVector() [1/4]

BitVector ( void  )
inline

◆ BitVector() [2/4]

BitVector ( int  size,
bool  set = false 
)

Build a bit vector of the given size.

Parameters
sizeCount of bits in the vector.
setInitial value of bits (default to 0).

References BitVector::set(), and BitVector::size().

◆ BitVector() [3/4]

BitVector ( const BitVector vec)

Build a vector by copying the given one.

Parameters
vecVector to copy.

◆ BitVector() [4/4]

BitVector ( const BitVector vec,
int  new_size 
)

Build a vector by extending or reducing the given one.

Parameters
vecVector to extend or to reduce.
new_sizeSize of the built vector.

◆ ~BitVector()

~BitVector ( void  )
inline

Member Function Documentation

◆ __size()

t::size __size ( void  ) const
inline

◆ applyAnd()

void applyAnd ( const BitVector vec)

Apply the AND-operation on this vector with given one.

Parameters
vecVector to process with.

Referenced by BitVector::operator&=().

◆ applyNot()

void applyNot ( void  )

Apply NOT-operator on the current vector.

◆ applyOr()

void applyOr ( const BitVector vec)

Apply the OR-operation on this vector with given one.

Parameters
vecVector to process with.

Referenced by BitVector::operator+=(), and BitVector::operator|=().

◆ applyReset()

void applyReset ( const BitVector vec)

Apply the RESET-operation (current & ~vec) on this vector with given one.

Parameters
vecVector to process with.

Referenced by BitVector::operator-=().

◆ begin()

OneIterator begin ( ) const
inline

◆ bit()

bool bit ( int  index) const
inline

Get the value of a bit. It is an error to pass index higher than vector size.

Parameters
indexBit index.
Returns
Value of the bit.

Referenced by BitVector::Ref::get(), BitVector::Iter::item(), AbstractBlockAllocatorWithGC::mark(), BitVector::OneIterator::next(), BitVector::ZeroIterator::next(), BitVector::operator[](), and BitVector::print().

◆ clear() [1/2]

void clear ( int  index) const
inline

Set a bit to false.

Parameters
indexIndex of the bit to set. It must be higher or equal to vector size.

Referenced by BitVector::Ref::clear().

◆ clear() [2/2]

void clear ( void  )

Set to false all bits in the vector.

Referenced by BitVector::set().

◆ copy()

void copy ( const BitVector vec) const

Copy the giuven vector in the current vector.

Parameters
vecVector to copy from.

Referenced by BitVector::operator=().

◆ countBits()

int countBits ( void  ) const

Count the number of bits whose value is 1.

References elm::ones().

Referenced by BitVector::countZeroes().

◆ countOnes()

int countOnes ( void  ) const

Count the number of ones in the vector.

Returns
Number of ones.

References elm::ones().

Referenced by BitVector::countZeroes().

◆ countZeroes()

int countZeroes ( void  ) const
inline

Count the number of zeroes in the vector.

Returns
Number of zeroes.

References BitVector::countBits(), and BitVector::countOnes().

◆ end()

OneIterator end ( ) const
inline

References BitVector::size().

◆ equals()

bool equals ( const BitVector vec) const

Test if two vectors are equals.

Parameters
vecSecond vector to test with.
Returns
True if the vectors are equal, false else.

Referenced by BitVector::operator!=(), and BitVector::operator==().

◆ includes()

bool includes ( const BitVector vec) const

Test if the current vector includes the given one.

Parameters
vecVector to use.
Returns
True if the inclusion holds, false else.

Referenced by BitVector::operator<=(), and BitVector::operator>=().

◆ includesStrictly()

bool includesStrictly ( const BitVector vec) const

Test if the current vector includes strictly the given one.

Parameters
vecVector to use.
Returns
True if the strict inclusion holds, false else.

Referenced by BitVector::operator<(), and BitVector::operator>().

◆ isEmpty()

bool isEmpty ( void  ) const
inline

Test if the vector is empty.

Returns
True if no bit is set, false else.

Referenced by BitVector::operator bool().

◆ makeAnd()

BitVector makeAnd ( const BitVector vec) const

Build a new vector as the result of operation AND on the current vector and the given one.

Parameters
vecSecond vector of operation.
Returns
Result of AND operation.

Referenced by BitVector::operator&().

◆ makeNot()

BitVector makeNot ( void  ) const

Build a new vector as the result of operation NOT of the current vector.

Returns
Result of NOT on current vector.

Referenced by BitVector::operator~().

◆ makeOr()

BitVector makeOr ( const BitVector vec) const

Build a new vector as the result of operation OR on the current vector and the given one.

Parameters
vecSecond vector of operation.
Returns
Result of OR operation.

Referenced by BitVector::operator+(), and BitVector::operator|().

◆ makeReset()

BitVector makeReset ( const BitVector vec) const

Build a new vector as the result of operation RESET on the current vector and the given one.

Parameters
vecSecond vector of operation.
Returns
Result of RESET operation.

Referenced by BitVector::operator-().

◆ meets()

bool meets ( const BitVector bv)

Test if vectors have some bit to 1 in common.

Parameters
bvBit vector to compare with.
Returns
True if there is something common, false else.

References elm::min().

◆ operator bool()

operator bool ( void  ) const
inline

Same as NOT isEmpty().

References BitVector::isEmpty().

◆ operator!=()

bool operator!= ( const BitVector vec) const
inline

Same as NOT equals().

References BitVector::equals().

◆ operator&()

BitVector operator& ( const BitVector vec) const
inline

Same as makeAnd().

References BitVector::makeAnd().

◆ operator&=()

BitVector & operator&= ( const BitVector vec)
inline

Same as applyAnd().

References BitVector::applyAnd().

◆ operator+()

BitVector operator+ ( const BitVector vec) const
inline

Same makeOr().

References BitVector::makeOr().

◆ operator+=()

BitVector & operator+= ( const BitVector vec)
inline

Same as applyOr().

References BitVector::applyOr().

◆ operator-()

BitVector operator- ( const BitVector vec) const
inline

Same as makeReset().

References BitVector::makeReset().

◆ operator-=()

BitVector & operator-= ( const BitVector vec)
inline

◆ operator<()

bool operator< ( const BitVector vec) const
inline

◆ operator<=()

bool operator<= ( const BitVector vec) const
inline

Same as includes().

References BitVector::includes().

◆ operator=()

BitVector & operator= ( const BitVector vec)

Same as copy().

References BitVector::copy().

◆ operator==()

bool operator== ( const BitVector vec) const
inline

Same as equals().

References BitVector::equals().

◆ operator>()

bool operator> ( const BitVector vec) const
inline

Reverse form of includesStricly().

References BitVector::includesStrictly().

◆ operator>=()

bool operator>= ( const BitVector vec) const
inline

Reverse form of includes().

References BitVector::includes().

◆ operator[]() [1/2]

Ref operator[] ( int  i)
inline

◆ operator[]() [2/2]

bool operator[] ( int  index) const
inline

Same as bit().

References BitVector::bit().

◆ operator|()

BitVector operator| ( const BitVector vec) const
inline

Same as makeOr().

References BitVector::makeOr().

◆ operator|=()

BitVector & operator|= ( const BitVector vec)
inline

Same as applyOr().

References BitVector::applyOr().

◆ operator~()

BitVector operator~ ( void  ) const
inline

Same as makeNot().

References BitVector::makeNot().

◆ print()

void print ( io::Output out) const

Print the bit vector in a binary form.

Parameters
outOutput to use.

References BitVector::bit(), and BitVector::size().

Referenced by elm::operator<<().

◆ resize()

void resize ( int  new_size)

Resize the vector.

Parameters
new_sizeNew size (in bits).

References elm::array::copy(), and elm::min().

◆ set() [1/3]

void set ( int  index) const
inline

Set to true a bit.

Parameters
indexIndex of the bit to set. It must be higher or equal to vector size.

Referenced by AbstractBlockAllocatorWithGC::mark(), and BitVector::Ref::set().

◆ set() [2/3]

void set ( int  index,
bool  value 
) const
inline

Set the value of a bit.

Parameters
indexIndex of the bit to set. It must be higher or equal to vector size.
valueValue of the bit.

References BitVector::clear(), and BitVector::set().

◆ set() [3/3]

void set ( void  )

◆ size()

int size ( void  ) const
inline

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