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;
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;
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Neighbor-index data structure for nix-vector routing.
NixVector & operator=(const NixVector &o)
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
void PrintDec2BinNix(uint32_t decimalNum, uint32_t bitCount, std::ostream &os) const
Internal for pretty printing of nix-vector (no fill)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
uint32_t m_totalBitSize
A counter of how total bits are in the nix-vector.
uint32_t GetRemainingBits(void)
uint32_t ExtractNeighborIndex(uint32_t numberOfBits)
uint32_t Serialize(uint32_t *buffer, uint32_t maxSize) const
NixBits_t m_nixVector
the actual nix-vector
uint32_t GetSerializedSize(void) const
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
void DumpNixVector(std::ostream &os) const
Print the NixVector.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::vector< uint32_t > NixBits_t
typedef for the nixVector
Ptr< NixVector > Copy(void) const
uint32_t BitCount(uint32_t numberOfNeighbors) const
void PrintDec2BinNixFill(uint32_t decimalNum, uint32_t bitCount, std::ostream &os) const
Internal for pretty printing of nix-vector (fill)
uint32_t Deserialize(const uint32_t *buffer, uint32_t size)
uint32_t m_used
For tracking where we are in the nix-vector.
void AddNeighborIndex(uint32_t newBits, uint32_t numberOfBits)
uint32_t m_currentVectorBitSize
For tracking how many bits we have used in the current vector entry.