本来仅仅只是用来做哈夫曼实验时的辅助,后来一想干脆封装好,省得以后又要用到比特位的操作。
基本用法示例:
BitArray bits;
bits[] = ;
bits[] = ;
cout<<bits[]<<endl; ]<<endl; ]<<endl; ){}
)/+;}
*bytes;}
size_t setBitCapacity(size_t newBitsCapacity);
size_t getBitSize(){ size_t getBitCapacity(){ size_t getByteSize(){ size_t getByteCapacity(){ uchar * m_data;
size_t m_bitsLength;
size_t m_bitsCapacity;
};
#endif
bits[] = ;
bits[] = ;
cout<<bits[]<<endl; ]<<endl; ]<<endl; ){}
)/+;}
*bytes;}
size_t setBitCapacity(size_t newBitsCapacity);
size_t getBitSize(){ size_t getBitCapacity(){ size_t getByteSize(){ size_t getByteCapacity(){ uchar * m_data;
size_t m_bitsLength;
size_t m_bitsCapacity;
};
#endif
1 #include "BitArray.h"
;
){
;
,t_bytesLength);
*t_bytesLength;
*t_fact_bytesCapacity;
,t_fact_bytesCapacity);
;i<m_bitsLength;i++){
}
BitArray::BitArray(unsigned {
m_data = data;
m_bitsLength = bitsLength;
m_bitsCapacity = *BitsToBytes(m_bitsLength);
m_owns = isOwns;
size_t t_bytesLength = BitsToBytes(m_bitsLength);
memset(m_data,,t_bytesLength);
}
delete[] m_data;
m_data = data;
m_bitsLength = bitsLength;
m_bitsCapacity = *BitsToBytes(m_bitsLength);
m_owns = isOwns;
size_t t_bytesLength = BitsToBytes(m_bitsLength);
memset(m_data,,t_bytesLength);
}
{
}
}
}
){
position += m_bitsLength;
}
} ;
} size_t t_new_bitsLength = position+;
size_t t_new_bytesCapacity = BitsToBytes(c_increaseCapacity*t_new_bitsLength);
size_t t_new_bitsCapacity = *t_new_bytesCapacity;
uchar* t_data = memset(t_data,,t_new_bytesCapacity);
memcpy(t_data,m_data,BitsToBytes(m_bitsCapacity));
delete[] m_data;
}
m_data = t_data;
m_bitsCapacity = t_new_bitsCapacity;
m_bitsLength = t_new_bitsLength;
m_owns = }
}
{
}
&& position >= -( }
}
size_t BitArray::setBitSize(size_t newBitsLength)
{
size_t origin_bitsLength = m_bitsLength;
m_bitsLength = newBitsLength;
} , }
}
size_t BitArray::setBitCapacity(size_t newBitsCapacity)
{
size_t new_bytesCapacity = BitsToBytes(newBitsCapacity);
uchar* t_data = memset(t_data,,new_bytesCapacity);
} }
delete[] m_data;
}
m_data = t_data;
m_bitsCapacity = BytesToBits(new_bytesCapacity);
m_bitsLength = m_bitsCapacity;
}
m_owns = }
}
{
m_owns = owns;
}
{
;
- (position) % ;
map[sub] |= <<pos; map[sub] &= ~(<<pos); }
{
;
- (position)%;
);
}
Bit::Bit(BitArray *bits, m_bits = bits;
m_position = position;
}
Bit& Bit:: m_bits-> }
Bit:: }
){
;
,t_bytesLength);
*t_bytesLength;
*t_fact_bytesCapacity;
,t_fact_bytesCapacity);
;i<m_bitsLength;i++){
}
BitArray::BitArray(unsigned {
m_data = data;
m_bitsLength = bitsLength;
m_bitsCapacity = *BitsToBytes(m_bitsLength);
m_owns = isOwns;
size_t t_bytesLength = BitsToBytes(m_bitsLength);
memset(m_data,,t_bytesLength);
}
delete[] m_data;
m_data = data;
m_bitsLength = bitsLength;
m_bitsCapacity = *BitsToBytes(m_bitsLength);
m_owns = isOwns;
size_t t_bytesLength = BitsToBytes(m_bitsLength);
memset(m_data,,t_bytesLength);
}
{
}
}
}
){
position += m_bitsLength;
}
} ;
} size_t t_new_bitsLength = position+;
size_t t_new_bytesCapacity = BitsToBytes(c_increaseCapacity*t_new_bitsLength);
size_t t_new_bitsCapacity = *t_new_bytesCapacity;
uchar* t_data = memset(t_data,,t_new_bytesCapacity);
memcpy(t_data,m_data,BitsToBytes(m_bitsCapacity));
delete[] m_data;
}
m_data = t_data;
m_bitsCapacity = t_new_bitsCapacity;
m_bitsLength = t_new_bitsLength;
m_owns = }
}
{
}
&& position >= -( }
}
size_t BitArray::setBitSize(size_t newBitsLength)
{
size_t origin_bitsLength = m_bitsLength;
m_bitsLength = newBitsLength;
} , }
}
size_t BitArray::setBitCapacity(size_t newBitsCapacity)
{
size_t new_bytesCapacity = BitsToBytes(newBitsCapacity);
uchar* t_data = memset(t_data,,new_bytesCapacity);
} }
delete[] m_data;
}
m_data = t_data;
m_bitsCapacity = BytesToBits(new_bytesCapacity);
m_bitsLength = m_bitsCapacity;
}
m_owns = }
}
{
m_owns = owns;
}
{
;
- (position) % ;
map[sub] |= <<pos; map[sub] &= ~(<<pos); }
{
;
- (position)%;
);
}
Bit::Bit(BitArray *bits, m_bits = bits;
m_position = position;
}
Bit& Bit:: m_bits-> }
Bit:: }
05-07 15:47