22 #include "ns3/fatal-error.h"
35 m_currentVectorBitSize (0),
49 : m_nixVector (o.m_nixVector),
51 m_currentVectorBitSize (o.m_currentVectorBitSize),
52 m_totalBitSize (o.m_totalBitSize)
92 if (numberOfBits > 32)
94 NS_FATAL_ERROR (
"Can't add more than 32 bits to a nix-vector at one time");
120 uint32_t tempBits = newBits;
154 m_currentVectorBitSize += numberOfBits;
164 if (numberOfBits > 32)
166 NS_FATAL_ERROR (
"Can't extract more than 32 bits to a nix-vector at one time");
169 uint32_t vectorIndex = 0;
170 uint32_t extractedBits = 0;
173 if (numberOfBits > totalRemainingBits)
175 NS_FATAL_ERROR (
"You've tried to extract too many bits of the Nix-vector, " <<
this <<
". NumberBits: "
176 << numberOfBits <<
" Remaining: " << totalRemainingBits);
179 if (numberOfBits <= 0)
181 NS_FATAL_ERROR (
"You've specified a number of bits for Nix-vector <= 0!");
188 vectorIndex = ((totalRemainingBits-1) / 32);
194 if ((numberOfBits-1) > ((totalRemainingBits-1) % 32))
196 extractedBits =
m_nixVector.at (vectorIndex) << (32 - (totalRemainingBits % 32));
197 extractedBits = extractedBits >> ((32 - (totalRemainingBits % 32))
198 - (numberOfBits - (totalRemainingBits % 32)));
200 >> (32 - (numberOfBits - (totalRemainingBits % 32))));
202 return extractedBits;
207 extractedBits =
m_nixVector.at (vectorIndex) << (32 - (totalRemainingBits % 32));
208 extractedBits = extractedBits >> (32 - (numberOfBits));
210 return extractedBits;
217 uint32_t totalSizeInBytes = 0;
221 return totalSizeInBytes;
228 uint32_t* p = buffer;
231 if (size + 4 <= maxSize)
242 if (size + 4 <= maxSize)
254 if (size + 4 <= maxSize)
266 if (size + 4 <= maxSize)
285 const uint32_t* p = buffer;
286 uint32_t sizeCheck = size - 4;
303 while (sizeCheck > 0)
315 return (sizeCheck != 0) ? 0 : 1;
323 std::vector<uint32_t>::const_reverse_iterator rIter;
326 uint32_t numBits =
BitCount (*rIter);
371 uint32_t bitCount = 0;
373 if (numberOfNeighbors < 2)
379 for (numberOfNeighbors -= 1; numberOfNeighbors != 0; numberOfNeighbors >>= 1)
393 for (; bitCount > 0; bitCount--)
401 for (; bitCount > 1; bitCount--)
410 os << decimalNum % 2;
428 if ((uint32_t)(
sizeof (uint32_t)*8) > bitCount)
430 for (uint32_t i = ((
sizeof (uint32_t)*8)-bitCount); i > 0; i--)
440 os << decimalNum % 2;
NixVector()
typedef for the nixVector
#define NS_LOG_FUNCTION(parameters)
Neighbor-index data structure for nix-vector routing.
Ptr< NixVector > Copy(void) const
NixVector & operator=(const NixVector &o)
#define NS_ASSERT(condition)
#define NS_FATAL_ERROR(msg)
fatal error handling
uint32_t GetRemainingBits(void)
uint32_t ExtractNeighborIndex(uint32_t numberOfBits)
void PrintDec2BinNix(uint32_t, uint32_t, std::ostream &os) const
void PrintDec2BinNixFill(uint32_t, uint32_t, std::ostream &os) const
uint32_t Serialize(uint32_t *buffer, uint32_t maxSize) const
void DumpNixVector(std::ostream &os) const
uint32_t GetSerializedSize(void) const
NS_LOG_COMPONENT_DEFINE("NixVector")
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
std::vector< uint32_t > NixBits_t
uint32_t Deserialize(const uint32_t *buffer, uint32_t size)
void AddNeighborIndex(uint32_t newBits, uint32_t numberOfBits)
uint32_t m_currentVectorBitSize
uint32_t BitCount(uint32_t numberOfNeighbors) const