本文整理汇总了C++中BitString类的典型用法代码示例。如果您正苦于以下问题:C++ BitString类的具体用法?C++ BitString怎么用?C++ BitString使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了BitString类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Expect
void ScrDB::Expect(TARGETING::TargetHandle_t i_ptargetHandle,
BitString & bs,
uint64_t registerId)
{
PRDF_TRAC( "ScrDB::Expect() huid: %X, addr: %016X, data: %08X %08X",
getHuid(i_ptargetHandle), registerId,
bs.getFieldJustify(0,32), bs.getFieldJustify(32,32) );
SimScrDataSet eValues;
DataList data;
// parse all data given
data.push_back(bs.getFieldJustify(0,32));
data.push_back(bs.getFieldJustify(32,32));
eValues.AddData(data);
// PRDF_TRAC("get a copy");
PreScrMap scrMap = eChipset[i_ptargetHandle]; // create/get copy of map
// PRDF_TRAC("update register value");
scrMap[registerId] = eValues; // Add entree
// PRDF_TRAC("update the master");
eChipset[i_ptargetHandle] = scrMap; // copy it back
//PRDF_EXIT( "ScrDB::Expect()" );
}
示例2: retrieveSubtree
DecodingTree*
Huffman::obtainSubtree(uint symbol, uint k)
{
BinaryNode *node = tree;
// Traversing the Huffman tree
for (uint i=1; i<=k; i++)
{
bool bit = ((symbol >> (k-i)) & 1);
if (bit == 0) node = node->leftChild;
else node = node->rightChild;
}
// Retrieving the subtree
vector<uint> xTree;
vector<uint> symbols;
uint bits = 0;
retrieveSubtree(node, &xTree, &bits, &symbols);
BitString *tree = new BitString(2*xTree.size());
for (uint i=0; i<xTree.size(); i++) tree->setBit(xTree[i]);
return new DecodingTree(symbol, tree, &symbols);
}
示例3: encode_data_and_push_into_bit_string
BitString<Char> encode_data_and_push_into_bit_string()const
{
BitString<Char> encoded;
for (auto ch : data)
encoded.push_back_bits(code_dictionary.at(ch));
return encoded;
}
示例4: generateBitmap
pair<BitString *,uint> generateBitmap(size_t length,vector<pair<uint,uint> > &nodes ) {
uint bitmap_pos = 0;
BitString *bitmap = new BitString(length);
size_t a,b;
cst->Root(&a,&b);
bitmap_pos++;
// cout << "(" ;
generateBitmapAux(make_pair(a,b),bitmap,bitmap_pos,nodes);
bitmap->setBit(bitmap_pos);
bitmap_pos++;
// cout << ")";
// cout << "nodes.size() = " << nodes.size() << endl;
BitString *new_bitmap = new BitString(bitmap->getData(),bitmap_pos);
// for (int i = 0 ; i < nodes.size();i++) {
// cout << nodes[i].first << endl;
// }
// cout << "=========== tree ==========" << endl;
// for (int i = 0 ;i < bitmap_pos;i++) {
// if (bitmap->getBit(i))
// cout << ")";
// else
// cout << "(";
// }
// cout << endl;
return make_pair(new_bitmap,bitmap_pos);
}
示例5: BuildRank
BitSequenceRG::BitSequenceRG(const BitString & bs, uint _factor) {
/*cout << "*****" << endl;
cout << bitarray << endl;
cout << _n << endl;
cout << _factor << endl; */
const uint * bitarray = bs.getData();
size_t _n = bs.getLength();
if(_factor==0) exit(-1);
data=new uint[_n/W+1];
for(size_t i=0;i<uint_len(_n,1);i++)
data[i] = bitarray[i];
for(size_t i=uint_len(_n,1);i<_n/W+1;i++)
data[i] = 0;
//this->owner = true;
this->n=_n;
uint lgn=bits(n-1);
this->factor=_factor;
if (_factor==0) this->factor=lgn;
else this->factor=_factor;
b=32;
s=b*this->factor;
integers = n/W+1;
BuildRank();
this->length = n;
this->ones = rank1(n-1);
}
示例6: PRDF_ASSERT
void BitString::setPattern( uint32_t i_sPos, uint32_t i_sLen,
CPU_WORD i_pattern, uint32_t i_pLen )
{
PRDF_ASSERT(nullptr != getBufAddr()); // must to have a valid address
PRDF_ASSERT(0 < i_sLen); // must have at least one bit
PRDF_ASSERT(i_sPos + i_sLen <= getBitLen()); // field must be within range
PRDF_ASSERT(0 < i_pLen); // must have at least one bit
PRDF_ASSERT(i_pLen <= CPU_WORD_BIT_LEN); // i_pLen length must be valid
// Get a bit string for the pattern subset (right justified).
BitString bso ( i_pLen, &i_pattern, CPU_WORD_BIT_LEN - i_pLen );
// Iterate the range in chunks the size of i_pLen.
uint32_t endPos = i_sPos + i_sLen;
for ( uint32_t pos = i_sPos; pos < endPos; pos += i_pLen )
{
// The true chunk size is either i_pLen or the leftovers at the end.
uint32_t len = std::min( i_pLen, endPos - pos );
// Get this chunk's pattern value, truncate (left justified) if needed.
CPU_WORD pattern = bso.getField( 0, len );
// Set the pattern in this string.
setField( pos, len, pattern );
}
}
示例7: for
void FeatureNumList::ToBitString (BitString& bitStr) const
{
bitStr.ReSet ();
kkint32 x;
for (x = 0; x < NumOfFeatures (); x++)
bitStr.Set (featureNums[x]);
} /* ToBitString */
示例8: Exists
bool QuadTree_S::Exists(const BitString &code, int x, int y) {
DeltaCode delta;
uint64_t cur = 0;
long long nodes = delta.DecodeNextInt(code, &cur);
long long size = code.get_length();
long long nextIndx = 0;
long long begRow = 0, begCol = 0, endRow = nodes, endCol = nodes;
long long depth = 0, nodesAtDepth = 1, nodesAtNextDepth = 0;
for (long long i = 0; i < size;) {
for(long long j = i; j < nodesAtDepth + i; j++) {
int curQuad = code.GetBit((j*2+cur)) << 1 | code.GetBit((j*2)+cur+1);
if (j == nextIndx) {
if (curQuad == 3) {
double midRow = ((double)begRow + endRow)/2;
double midCol = ((double)begCol + endCol)/2;
if (x < midRow) { //We are in NE or NW
if (y < midCol) { //We are in NW
endRow = midRow;
endCol = midCol;
nextIndx = i + nodesAtDepth + nodesAtNextDepth;
} else { //We are in NE
endRow = midRow;
begCol = midCol;
nextIndx = i + nodesAtDepth + nodesAtNextDepth + 1;
}
} else if (y < midCol) { //We are in SW
begRow = midRow;
endCol = midCol;
nextIndx = i + nodesAtDepth + nodesAtNextDepth + 2;
} else { //We are in SE
begRow = midRow;
begCol = midCol;
nextIndx = i + nodesAtDepth + nodesAtNextDepth + 3;
}
nodesAtNextDepth += 4;
int nextQuad = code.GetBit((nextIndx*2)+cur) << 1 | code.GetBit((nextIndx*2)+cur+1);
if (nextQuad == 1) return true;
if (nextQuad == 0) return false;
else if (nextQuad == 2)
if (begCol-begRow + x == y) return false;
else return true;
}
else if (curQuad == 1) return true;
else if (curQuad == 0) return false;
else if (curQuad == 2) {
if (begCol-begRow + x == y) return false;
else return true;
}
} else if (curQuad == 3) {
nodesAtNextDepth += 4;
}
}
i += nodesAtDepth;
nodesAtDepth = nodesAtNextDepth;
nodesAtNextDepth = 0;
}
}
示例9: setString
void BitString::setString( const BitString & i_sStr, uint32_t i_sPos,
uint32_t i_sLen, uint32_t i_dPos )
{
// Ensure the source parameters are valid.
PRDF_ASSERT( nullptr != i_sStr.getBufAddr() );
PRDF_ASSERT( 0 < i_sLen ); // at least one bit to copy
PRDF_ASSERT( i_sPos + i_sLen <= i_sStr.getBitLen() );
// Ensure the destination has at least one bit available to copy.
PRDF_ASSERT( nullptr != getBufAddr() );
PRDF_ASSERT( i_dPos < getBitLen() );
// If the source length is greater than the destination length than the
// extra source bits are ignored.
uint32_t actLen = std::min( i_sLen, getBitLen() - i_dPos );
// The bit strings may be in overlapping memory spaces. So we need to copy
// the data in the correct direction to prevent overlapping.
uint32_t sRelOffset = 0, dRelOffset = 0;
CPU_WORD * sRelAddr = i_sStr.getRelativePosition( sRelOffset, i_sPos );
CPU_WORD * dRelAddr = getRelativePosition( dRelOffset, i_dPos );
// Copy the data.
if ( (dRelAddr == sRelAddr) && (dRelOffset == sRelOffset) )
{
// Do nothing. The source and destination are the same.
}
else if ( (dRelAddr < sRelAddr) ||
((dRelAddr == sRelAddr) && (dRelOffset < sRelOffset)) )
{
// Copy the data forward.
for ( uint32_t pos = 0; pos < actLen; pos += CPU_WORD_BIT_LEN )
{
uint32_t len = std::min( actLen - pos, CPU_WORD_BIT_LEN );
CPU_WORD value = i_sStr.getField( i_sPos + pos, len );
setField( i_dPos + pos, len, value );
}
}
else // Copy the data backwards.
{
// Get the first position of the last chunk (CPU_WORD aligned).
uint32_t lastPos = ((actLen-1) / CPU_WORD_BIT_LEN) * CPU_WORD_BIT_LEN;
// Start with the last chunk and work backwards.
for ( int32_t pos = lastPos; 0 <= pos; pos -= CPU_WORD_BIT_LEN )
{
uint32_t len = std::min( actLen - pos, CPU_WORD_BIT_LEN );
CPU_WORD value = i_sStr.getField( i_sPos + pos, len );
setField( i_dPos + pos, len, value );
}
}
}
示例10: if
std::vector<int> QuadTree_S::GetNeighbors(const BitString &code, int x) {
DeltaCode delta;
uint64_t cur = 0;
int nodes = delta.DecodeNextInt(code, &cur);
long long size = code.get_length();
std::vector<int> neighbors;
QueueObj pos;
std::queue<QueueObj> posQueue;
posQueue.push(QueueObj(0, 0, nodes, 0, nodes));
pos = posQueue.front();
long long depth = 0, nodesAtDepth = 1, nodesAtNextDepth = 0;
for(int i = 0; !posQueue.empty();) {
for(long long j = i; j < nodesAtDepth + i; j++) {
int curQuad = code.GetBit((j*2+cur)) << 1 | code.GetBit((j*2)+cur+1);
if (j == pos.nextPos) {
posQueue.pop();
if (curQuad == 3) {
double midRow = ((double)pos.begRow + pos.endRow)/2;
double midCol = ((double)pos.begCol + pos.endCol)/2;
if (x < midRow) {
posQueue.push(QueueObj(i + nodesAtDepth + nodesAtNextDepth, pos.begRow, midRow, pos.begCol, midCol));
posQueue.push(QueueObj(i + nodesAtDepth + nodesAtNextDepth + 1, pos.begRow, midRow, midCol, pos.endCol));
} else {
posQueue.push(QueueObj(i + nodesAtDepth + nodesAtNextDepth + 2, midRow, pos.endRow, pos.begCol, midCol));
posQueue.push(QueueObj(i + nodesAtDepth + nodesAtNextDepth + 3, midRow, pos.endRow, midCol, pos.endCol));
}
nodesAtNextDepth += 4;
}
else if (curQuad == 1) {
for (int n = pos.begCol; n < pos.endCol; ++n) {
neighbors.push_back(n);
}
}
else if (curQuad == 2) {
for (int n = pos.begCol; n < pos.endCol; ++n) {
if (pos.begCol - pos.begRow + x == n) continue;
neighbors.push_back(n);
}
}
if (posQueue.empty()) break;
pos = posQueue.front();
} else if (curQuad == 3){
nodesAtNextDepth += 4;
}
}
i += nodesAtDepth;
nodesAtDepth = nodesAtNextDepth;
nodesAtNextDepth = 0;
}
return neighbors;
}
示例11: Read
void ScrDB::Read(TARGETING::TargetHandle_t i_ptargetHandle,
BitString & bs,
uint64_t registerId)
{
//PRDF_DENTER( "ScrDB::Read() huid: 0x%X, addr: 0x%016X",
// getHuid(i_ptargetHandle), registerId );
DataList data;
unsigned int dataWordSize = bs.getBitLen()/32;
dataWordSize += (bs.getBitLen() % 32) ? 1 : 0;
// if the register has a predetermined value than get it
if(pChipset.find(i_ptargetHandle) != pChipset.end())
{
PreScrMap pscrmap = pChipset[i_ptargetHandle];
if(pscrmap.find(registerId) != pscrmap.end()) // we must have a predetermined value
{
SimScrDataSet pValues = pscrmap[registerId];
data = pValues.GetData(); // get next set of values
// pValues has changed - copy it back
pscrmap[registerId] = pValues;
pChipset[i_ptargetHandle] = pscrmap;
}
}
if(data.size() == 0) // use the last value written to this reg
{
// get a copy of the scrMap for this chip - if one does not exist it will be created
ScrMap scrMap = chipset[i_ptargetHandle];
// get a copy of the data for this address from the scrMap for this chip
// if data structure does not exist, it will be created, but will be empty
data = scrMap[registerId];
if(data.size() == 0) // This is the first time this register has been accessed
{
while(data.size() < dataWordSize) data.push_back(0); // zero fill
scrMap[registerId] = data;
chipset[i_ptargetHandle] = scrMap; // update the persistent copy of the scrMap
}
}
if(0 != data.size())
{
for(unsigned int i = 0; i < data.size(); ++i)
{
bs.setFieldJustify((i*32), 32, data[i]);
}
PRDF_TRAC( "ScrDB::Read() huid: %X, addr: %016X, data: %08X %08X",
getHuid(i_ptargetHandle), registerId, data[0],
2 == data.size() ? data[1] : 0 );
}
//PRDF_DEXIT( "ScrDB::Read()" );
}
示例12: test_BitString
void test_BitString()
{
try
{
BitString x(30);
BitString y(30);
x.Set(3);
x.Set(7);
x.Set(14);
y.Set(3);
y.Set(5);
y.Set(12);
// Test out of bounds bit number handling
// y.Set(32);
std::cout << "X = " << x << std::endl;
std::cout << "Y = " << y << std::endl;
// Test bit-wise AND
// BitString z = x & y;
// std::cout << "X & Y = " << z << std::endl;
// Test bit-wise OR
// BitString z = x | y;
// std::cout << "X | Y = " << z << std::endl;
// Test bit-wise XOR
BitString z = x^y;
std::cout << "X ^ Y = " << z << std::endl;
// Test bit-wise Count
size_t c = z.Count();
std::cout << "Count X | Y = " << (int) c << std::endl;
}
// Catch any simple string error messages
catch( char* s )
{
std::cout << s << std::endl;
}
}
示例13:
BitSequenceSDArray::BitSequenceSDArray(const BitString & bs) {
uint * tmp_seq = new uint[uint_len(bs.getLength(),1)+1];
ones = 0;
for(uint i=0;i<uint_len(bs.getLength(),1)+1;i++)
tmp_seq[i] = 0;
for(uint i=0;i<bs.getLength();i++)
if(bs[i]) {
__setbit(tmp_seq,i,1);
ones++;
}
if(ones)
selects3_construct(&sd,bs.getLength(),tmp_seq);
this->length = bs.getLength();
delete [] tmp_seq;
}
示例14: isEqual
bool BitString::isEqual( const BitString & i_str ) const
{
if ( getBitLen() != i_str.getBitLen() )
return false; // size not equal
for ( uint32_t pos = 0; pos < getBitLen(); pos += CPU_WORD_BIT_LEN )
{
uint32_t len = std::min( getBitLen() - pos, CPU_WORD_BIT_LEN );
if ( getField(pos, len) != i_str.getField(pos, len) )
return false; // bit strings do not match
}
return true; // bit strings match
}
示例15: maskString
void BitString::maskString( const BitString & i_mask )
{
// Get the length of the smallest string.
uint32_t actLen = std::min( getBitLen(), i_mask.getBitLen() );
for ( uint32_t pos = 0; pos < actLen; pos += CPU_WORD_BIT_LEN )
{
uint32_t len = std::min( actLen - pos, CPU_WORD_BIT_LEN );
CPU_WORD dVal = getField( pos, len );
CPU_WORD sVal = i_mask.getField( pos, len );
setField( pos, len, dVal & ~sVal );
}
}