本文整理汇总了C++中BitVector::back_word方法的典型用法代码示例。如果您正苦于以下问题:C++ BitVector::back_word方法的具体用法?C++ BitVector::back_word怎么用?C++ BitVector::back_word使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitVector
的用法示例。
在下文中一共展示了BitVector::back_word方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testIterator
int testIterator (size_t n, size_t k)
{
commentator.start ("Testing BitSubvector::word_iterator", __FUNCTION__);
bool pass = true;
std::ostream &error = commentator.report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR);
BitVector<Endianness> v (n);
BitVector<Endianness>::word_iterator w;
unsigned int flip = 0;
for (w = v.word_begin (); w != v.word_end (); ++w, flip = 1 - flip)
*w = pattern[flip];
v.back_word () = pattern[flip];
size_t offset;
for (offset = 0; offset <= n - k; ++offset) {
BitSubvector<BitVector<Endianness>::iterator> vp (v.begin () + offset, v.begin () + (offset + k));
BitSubvector<BitVector<Endianness>::iterator>::word_iterator i;
BitSubvector<BitVector<Endianness>::iterator>::const_word_iterator j1, j2;
flip = ((offset / WordTraits<BitVector<Endianness>::word_type>::bits) % 2 == 0) ? 0 : 1;
for (i = vp.word_begin (), j1 = vp.word_begin (), j2 = vp.word_begin (); i != vp.word_end (); ++i, ++j1, ++j2, flip = 1 - flip) {
if (*j1 != *i) {
error << "ERROR: error at offset " << offset << " (n = " << n << ", k = " << k << ")" << std::endl;
error << "ERROR: word_iterator and const_word_iterator don't agree" << std::endl;
error << "ERROR: word_iterator: " << std::hex << *i << std::endl;
error << "ERROR: const_word_iterator: " << std::hex << *j1 << std::endl;
pass = false;
goto end_test;
}
BitVector<Endianness>::word_type val = *j1;
*i ^= val;
if (*j2 != 0) {
error << "ERROR: error at offset " << offset << " (n = " << n << ", k = " << k << ")" << std::endl;
error << "ERROR: Pattern should be 0 after clearing" << std::endl;
error << "ERROR: Detected " << std::hex << *j2 << std::endl;
pass = false;
goto end_test;
}
*i ^= val;
}
}
end_test:
commentator.stop (MSG_STATUS (pass));
return pass;
}
示例2: testConstIterator
bool testConstIterator (size_t n, size_t k)
{
commentator.start ("Testing BitSubvector::const_word_iterator", __FUNCTION__);
bool pass = true;
std::ostream &error = commentator.report (Commentator::LEVEL_IMPORTANT, INTERNAL_ERROR);
BitVector<Endianness> v (n);
BitVector<Endianness>::word_iterator w;
unsigned int flip = 0;
for (w = v.word_begin (); w != v.word_end (); ++w, flip = 1 - flip)
*w = pattern[flip];
v.back_word () = pattern[flip];
size_t offset;
for (offset = 0; offset <= n - k; ++offset) {
BitSubvector<BitVector<Endianness>::const_iterator> vp (v.begin () + offset, v.begin () + (offset + k));
BitSubvector<BitVector<Endianness>::const_iterator>::const_word_iterator i;
flip = ((offset / WordTraits<BitVector<Endianness>::word_type>::bits) % 2 == 0) ? 0 : 1;
size_t idx = 0;
for (i = vp.word_begin (); i != vp.word_end (); ++i, flip = 1 - flip, idx += WordTraits<BitVector<Endianness>::word_type>::bits) {
BitVector<Endianness>::word_type check = connect (pattern[flip], pattern[1-flip], offset % WordTraits<BitVector<Endianness>::word_type>::bits);
if (idx + WordTraits<BitVector<Endianness>::word_type>::bits > k)
check &= Endianness::mask_left (k % WordTraits<BitVector<Endianness>::word_type>::bits);
if (*i != check) {
error << "ERROR: error at offset " << offset << std::endl;
error << "ERROR: Pattern should be " << std::hex << check << std::endl;
error << "ERROR: Detected " << std::hex << *i << std::endl;
pass = false;
goto end_test;
}
}
}
end_test:
commentator.stop (MSG_STATUS (pass));
return pass;
}