INET Framework for OMNeT++/OMNEST
inet::ShortBitVector Class Reference

Optimized version of the BitVector class to store short bit vectors. More...

#include <ShortBitVector.h>

Public Member Functions

 ShortBitVector ()
 
 ShortBitVector (const char *bitString)
 
 ShortBitVector (unsigned int bits)
 
 ShortBitVector (unsigned int bits, unsigned int size)
 
 ShortBitVector (const ShortBitVector &other)
 
unsigned int toDecimal () const
 
unsigned int reverseToDecimal () const
 
void rightShift (int with)
 
void leftShift (int with)
 
void appendBit (bool value)
 
void appendBit (bool value, int n)
 
bool getBit (unsigned int pos) const
 
void setBit (unsigned int pos, bool value)
 
void toggleBit (unsigned int pos)
 
bool isEmpty () const
 
unsigned int getSize () const
 
unsigned int computeHammingDistance (const ShortBitVector &u) const
 
ShortBitVectoroperator= (const ShortBitVector &other)
 
bool operator== (const ShortBitVector &rhs) const
 
bool operator!= (const ShortBitVector &rhs) const
 
std::string toString () const
 

Private Member Functions

void copy (const ShortBitVector &other)
 

Private Attributes

unsigned int bits
 
unsigned int size
 

Friends

std::ostream & operator<< (std::ostream &out, const ShortBitVector &bitVector)
 

Detailed Description

Optimized version of the BitVector class to store short bit vectors.

Constructor & Destructor Documentation

inet::ShortBitVector::ShortBitVector ( )
24 {
25  size = 0;
26  bits = 0;
27 }
unsigned int size
Definition: ShortBitVector.h:32
unsigned int bits
Definition: ShortBitVector.h:31
inet::ShortBitVector::ShortBitVector ( const char *  bitString)
30 {
31  size = 0;
32  bits = 0;
33  int strSize = strlen(bitString);
34  for (int i = 0; i < strSize; i++) {
35  if (bitString[i] == '1')
36  appendBit(true);
37  else if (bitString[i] == '0')
38  appendBit(false);
39  else
40  throw cRuntimeError("str must represent a binary number");
41  }
42 }
unsigned int size
Definition: ShortBitVector.h:32
void appendBit(bool value)
Definition: ShortBitVector.h:66
unsigned int bits
Definition: ShortBitVector.h:31
inet::ShortBitVector::ShortBitVector ( unsigned int  bits)
45 {
46  if (num == 0)
47  size = 1;
48  else
49  size = (int)(log(num) / log(2)) + 1;
50  bits = num;
51 }
unsigned int size
Definition: ShortBitVector.h:32
unsigned int bits
Definition: ShortBitVector.h:31
inet::ShortBitVector::ShortBitVector ( unsigned int  bits,
unsigned int  size 
)
54 {
55  if (size > sizeof(unsigned int) * 8)
56  throw cRuntimeError("size = %d must be less than %d", size, sizeof(unsigned int) * 8);
57  this->size = size;
58  this->bits = bits;
59 }
unsigned int size
Definition: ShortBitVector.h:32
unsigned int bits
Definition: ShortBitVector.h:31
inet::ShortBitVector::ShortBitVector ( const ShortBitVector other)
inline
46 { copy(other); }
void copy(const ShortBitVector &other)
Definition: ShortBitVector.h:35

Member Function Documentation

void inet::ShortBitVector::appendBit ( bool  value,
int  n 
)
inline

Referenced by appendBit().

68 { while (n--) appendBit(value); }
void appendBit(bool value)
Definition: ShortBitVector.h:66
unsigned int inet::ShortBitVector::computeHammingDistance ( const ShortBitVector u) const
inline
107  {
108 #ifndef NDEBUG
109  if (getSize() != u.getSize())
110  throw cRuntimeError("You can't compute Hamming distance between two vectors with different sizes");
111 #endif
112  unsigned int hammingDistance = bits ^ u.toDecimal();
113  hammingDistance = hammingDistance - ((hammingDistance >> 1) & 0x55555555);
114  hammingDistance = (hammingDistance & 0x33333333) + ((hammingDistance >> 2) & 0x33333333);
115  return (((hammingDistance + (hammingDistance >> 4)) & 0x0F0F0F0F) * 0x01010101) >> 24;
116  }
unsigned int getSize() const
Definition: ShortBitVector.h:104
unsigned int bits
Definition: ShortBitVector.h:31
void inet::ShortBitVector::copy ( const ShortBitVector other)
inlineprivate
36  {
37  size = other.size;
38  bits = other.bits;
39  }
unsigned int size
Definition: ShortBitVector.h:32
unsigned int bits
Definition: ShortBitVector.h:31
bool inet::ShortBitVector::isEmpty ( ) const
inline
void inet::ShortBitVector::leftShift ( int  with)
inline
bool inet::ShortBitVector::operator!= ( const ShortBitVector rhs) const
inline
128 { return !(rhs == *this); }
ShortBitVector& inet::ShortBitVector::operator= ( const ShortBitVector other)
inline
119  {
120  if (this == &other)
121  return *this;
122  copy(other);
123  return *this;
124  }
void copy(const ShortBitVector &other)
Definition: ShortBitVector.h:35
bool inet::ShortBitVector::operator== ( const ShortBitVector rhs) const
inline
126 { return rhs.bits == bits; }
unsigned int bits
Definition: ShortBitVector.h:31
unsigned int inet::ShortBitVector::reverseToDecimal ( ) const
inline

Referenced by inet::physicallayer::ConvolutionalCoder::computeDecimalToOutputSymbolVector(), inet::physicallayer::ConvolutionalCoder::computeOutputAndInputSymbols(), inet::physicallayer::ConvolutionalCoder::computeStateTransitions(), inet::physicallayer::ConvolutionalCoder::encode(), and inet::physicallayer::ConvolutionalCoder::printOutputs().

51  {
52  unsigned int decimal = 0;
53  unsigned int powerOfTwo = 1;
54  for (int i = getSize() - 1; i >= 0; i--) {
55  if (getBit(i))
56  decimal += powerOfTwo;
57  powerOfTwo *= 2;
58  }
59  return decimal;
60  }
bool getBit(unsigned int pos) const
Definition: ShortBitVector.h:70
unsigned int getSize() const
Definition: ShortBitVector.h:104
void inet::ShortBitVector::rightShift ( int  with)
inline
62 { bits = bits >> with; }
unsigned int bits
Definition: ShortBitVector.h:31
void inet::ShortBitVector::setBit ( unsigned int  pos,
bool  value 
)
inline

Referenced by inet::physicallayer::ConvolutionalCoder::computeStateTransitions(), inet::physicallayer::LayeredErrorModelBase::computeSymbolModel(), inet::physicallayer::AdditiveScrambler::generateScramblingSequence(), inet::physicallayer::ConvolutionalCoder::giveNextOutputSymbol(), inet::physicallayer::ConvolutionalCoder::inputSymbolToOutputSymbol(), inet::physicallayer::APSKModulator::modulate(), and inet::physicallayer::Ieee80211OFDMModulator::modulate().

80  {
81 #ifndef NDEBUG
82  if (pos >= sizeof(unsigned int) * 8)
83  throw cRuntimeError("Out of range with bit position: %d", pos);
84 #endif
85  if (pos + 1 > size)
86  size = pos + 1;
87  if (value)
88  bits |= 1 << pos;
89  else
90  bits &= ~(1 << pos);
91  }
unsigned int size
Definition: ShortBitVector.h:32
unsigned int bits
Definition: ShortBitVector.h:31
void inet::ShortBitVector::toggleBit ( unsigned int  pos)
inline
94  {
95 #ifndef NDEBUG
96  if (pos >= size)
97  throw cRuntimeError("Out of range with bit position %d", pos);
98 #endif
99  bits ^= 1 << pos;
100  }
unsigned int size
Definition: ShortBitVector.h:32
unsigned int bits
Definition: ShortBitVector.h:31
std::string inet::ShortBitVector::toString ( ) const
75 {
76  std::string str;
77  for (unsigned int i = 0; i < getSize(); i++) {
78  if (getBit(i))
79  str += "1";
80  else
81  str += "0";
82  }
83  return str;
84 }
bool getBit(unsigned int pos) const
Definition: ShortBitVector.h:70
unsigned int getSize() const
Definition: ShortBitVector.h:104

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  out,
const ShortBitVector bitVector 
)
friend
62 {
63  for (unsigned int i = 0; i < bitVector.getSize(); i++) {
64  if (i != 0)
65  out << " ";
66  if (bitVector.getBit(i))
67  out << "1";
68  else
69  out << "0";
70  }
71  return out;
72 }

Member Data Documentation

unsigned int inet::ShortBitVector::bits
private

Referenced by copy(), operator==(), and ShortBitVector().

unsigned int inet::ShortBitVector::size
private

Referenced by copy(), and ShortBitVector().


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