Naming fix

This commit is contained in:
disinvite 2024-03-13 20:52:43 -04:00
parent 7b278313e7
commit a4d2179378
2 changed files with 35 additions and 34 deletions

View File

@ -11,83 +11,84 @@
template <size_t N>
class MxBitset {
public:
MxBitset() { _Tidy(); }
MxBitset() { Tidy(); }
class reference {
class Reference {
friend class MxBitset<N>;
public:
reference& flip()
Reference& Flip()
{
m_bitset->flip(m_offset);
m_bitset->Flip(m_offset);
return (*this);
}
bool operator~() const { return (!m_bitset->test(m_offset)); }
operator bool() const { return (m_bitset->test(m_offset)); }
bool operator~() const { return (!m_bitset->Test(m_offset)); }
operator bool() const { return (m_bitset->Test(m_offset)); }
private:
reference(MxBitset<N>& _X, size_t _P) : m_bitset(&_X), m_offset(_P) {}
Reference(MxBitset<N>& p_bitset, size_t p_offset) : m_bitset(&p_bitset), m_offset(p_offset) {}
MxBitset<N>* m_bitset;
size_t m_offset;
};
reference operator[](size_t p_bit) { return (reference(*this, p_bit)); }
Reference operator[](size_t p_bit) { return (Reference(*this, p_bit)); }
MxBitset<N>& flip(size_t p_bit)
MxBitset<N>& Flip(size_t p_bit)
{
if (N <= p_bit) {
_Xran();
Xran();
}
m_blocks[p_bit / _bits_per_block] ^= 1 << p_bit % _bits_per_block;
m_blocks[p_bit / e_bitsPerBlock] ^= 1 << p_bit % e_bitsPerBlock;
return (*this);
}
size_t count()
size_t Count()
{
// debug only
return 0;
}
bool test(MxU32 p_bit)
bool Test(MxU32 p_bit)
{
if (p_bit >= N) {
_Xran();
Xran();
}
return (m_blocks[p_bit / _bits_per_block] & (1 << p_bit % _bits_per_block)) != 0;
return (m_blocks[p_bit / e_bitsPerBlock] & (1 << p_bit % e_bitsPerBlock)) != 0;
}
MxU32 size() const { return N; }
MxU32 Size() const { return N; }
private:
void _Tidy(MxU32 p_value = 0)
void Tidy(MxU32 p_value = 0)
{
for (MxS32 i = _blocks_required; i >= 0; --i) {
for (MxS32 i = e_blocksRequired; i >= 0; --i) {
m_blocks[i] = p_value;
}
// No need to trim if all bits were zeroed out
if (p_value != 0) {
_Trim();
Trim();
}
}
// Apply bit mask to most significant block
void _Trim()
void Trim()
{
if (N % _bits_per_block != 0) {
m_blocks[_blocks_required] &= ((1 << (N % _bits_per_block)) - 1);
if (N % e_bitsPerBlock != 0) {
m_blocks[e_blocksRequired] &= ((1 << (N % e_bitsPerBlock)) - 1);
}
}
void _Xran() { assert("invalid MxBitset<N> position" == NULL); }
void Xran() { assert("invalid MxBitset<N> position" == NULL); }
// Not a real enum. This is how STL BITSET defines these constants.
enum {
_bits_per_block = CHAR_BIT * sizeof(MxU32),
_blocks_required = N == 0 ? 0 : (N - 1) / _bits_per_block
e_bitsPerBlock = CHAR_BIT * sizeof(MxU32),
e_blocksRequired = N == 0 ? 0 : (N - 1) / e_bitsPerBlock
};
MxU32 m_blocks[_blocks_required + 1]; // 0x0
MxU32 m_blocks[e_blocksRequired + 1]; // 0x0
};
#endif // MXBITSET_H

View File

@ -17,7 +17,7 @@ class MxMemoryPool {
MxU8* Get();
void Release(MxU8*);
MxU32 GetPoolSize() const { return m_blockRef.size(); }
MxU32 GetPoolSize() const { return m_blockRef.Size(); }
private:
MxU8* m_pool;
@ -30,7 +30,7 @@ MxResult MxMemoryPool<BS, NB>::Allocate()
{
assert(m_pool == NULL);
assert(m_blockSize);
assert(m_blockRef.size());
assert(m_blockRef.Size());
m_pool = new MxU8[GetPoolSize() * m_blockSize * 1024];
assert(m_pool);
@ -43,16 +43,16 @@ MxU8* MxMemoryPool<BS, NB>::Get()
{
assert(m_pool != NULL);
assert(m_blockSize);
assert(m_blockRef.size());
assert(m_blockRef.Size());
for (MxU32 i = 0; i < GetPoolSize(); i++) {
if (!m_blockRef[i]) {
m_blockRef[i].flip();
m_blockRef[i].Flip();
#ifdef _DEBUG
// TODO: This is actually some debug print function, but
// we just need any func with variatic args to eliminate diff noise.
printf("Get> %d pool: busy %d blocks\n", m_blockSize, m_blockRef.count());
printf("Get> %d pool: busy %d blocks\n", m_blockSize, m_blockRef.Count());
#endif
return &m_pool[i * m_blockSize * 1024];
@ -67,7 +67,7 @@ void MxMemoryPool<BS, NB>::Release(MxU8* p_buf)
{
assert(m_pool != NULL);
assert(m_blockSize);
assert(m_blockRef.size());
assert(m_blockRef.Size());
MxU32 i = (MxU32) (p_buf - m_pool) / (m_blockSize * 1024);
@ -75,11 +75,11 @@ void MxMemoryPool<BS, NB>::Release(MxU8* p_buf)
assert(m_blockRef[i]);
if (m_blockRef[i]) {
m_blockRef[i].flip();
m_blockRef[i].Flip();
}
#ifdef _DEBUG
printf("Release> %d pool: busy %d blocks\n", m_blockSize, m_blockRef.count());
printf("Release> %d pool: busy %d blocks\n", m_blockSize, m_blockRef.Count());
#endif
}