Core/Bitset: Add Reverse() method
This commit is contained in:
@@ -66,6 +66,8 @@ namespace Nz
|
||||
void Reset();
|
||||
void Reset(std::size_t bit);
|
||||
|
||||
void Reverse();
|
||||
|
||||
void Set(bool val = true);
|
||||
void Set(std::size_t bit, bool val = true);
|
||||
void SetBlock(std::size_t i, Block block);
|
||||
|
||||
@@ -581,6 +581,30 @@ namespace Nz
|
||||
Set(bit, false);
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Reverse the order of bits in a bitset
|
||||
*
|
||||
* Reverse the order of bits in the bitset (first bit swap with the last one, etc.)
|
||||
*/
|
||||
template<typename Block, class Allocator>
|
||||
void Bitset<Block, Allocator>::Reverse()
|
||||
{
|
||||
if (m_bitCount == 0)
|
||||
return;
|
||||
|
||||
std::size_t i = 0;
|
||||
std::size_t j = m_bitCount - 1;
|
||||
|
||||
while (i < j)
|
||||
{
|
||||
bool bit1 = Test(i);
|
||||
bool bit2 = Test(j);
|
||||
|
||||
Set(i++, bit2);
|
||||
Set(j--, bit1);
|
||||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Sets the bitset to val
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user