本文整理汇总了C++中BitMatrix::SumColumns方法的典型用法代码示例。如果您正苦于以下问题:C++ BitMatrix::SumColumns方法的具体用法?C++ BitMatrix::SumColumns怎么用?C++ BitMatrix::SumColumns使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitMatrix
的用法示例。
在下文中一共展示了BitMatrix::SumColumns方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RandomPassiveSet
//-----------------------------------------------------------------------------
void RandomPassiveSet(BitMatrix& passive_set,
Random& rng,
const unsigned int height,
const unsigned int width)
{
passive_set.Resize(height, width);
unsigned int* buf_ps = passive_set.Buffer();
const unsigned int ldim = passive_set.LDim();
const unsigned int full_wds = height / BitMatrix::BITS_PER_WORD;
const unsigned int extra = height - BitMatrix::BITS_PER_WORD*full_wds;
const unsigned int MASK = passive_set.Mask();
// initial nonzero bit pattern to fill columns with
unsigned int pattern = 0x01;
// randomly shuffle the column indices of the passive set
std::vector<unsigned int> col_indices(width);
for (unsigned int q=0; q<width; ++q)
col_indices[q] = q;
if (width > 1)
FisherYatesShuffle(col_indices.begin(), col_indices.end(), rng);
for (unsigned int c=0; c<width; ++c)
{
unsigned int col_index = col_indices[c];
unsigned int col_offset = col_index * ldim;
// Fill this column with the bit pattern, ensuring that the
// final bits in each column (outside the MASK for the passive
// set matrix) are zero.
unsigned int r_wd=0;
for (; r_wd < full_wds; ++r_wd)
buf_ps[col_offset + r_wd] = pattern;
if (extra > 0)
{
unsigned int wd = MASK & pattern;
assert(wd > 0);
buf_ps[col_offset + r_wd] = wd;
}
// shift the pattern to the left one bit and OR in a new bit
pattern <<= 1;
pattern |= 1;
// start over if all ones
if (0xFFFFFFFF == pattern)
pattern = 0x01;
}
// None of the columns should contain all zero bits.
std::vector<unsigned int> col_sums(width);
passive_set.SumColumns(col_sums);
for (unsigned int c=0; c<width; ++c)
{
if (0 == col_sums[c])
{
unsigned int col_offset = c*ldim;
cout << "RandomPassiveSet: column " << c << " is a zero column." << endl;
cout << "Pattern: " << std::hex << pattern << std::dec << endl;
cout << "Height: " << height << ", width: " << width << endl;
cout << "full_wds: " << full_wds << endl;
cout << "extra: " << extra << endl;
cout << "Ldim: " << ldim << ", extra: " << extra << endl;
cout << "MASK: " << std::hex << MASK << std::dec << endl;
cout << "col_offset: " << col_offset << endl;
unsigned int r_wd = 0;
for (; r_wd<full_wds; ++r_wd)
cout << "words_[" << r_wd << "]: " << std::hex
<< buf_ps[col_offset + r_wd] << std::dec << endl;
if (MASK > 0)
{
unsigned int wd = MASK & buf_ps[col_offset + r_wd];
cout << "words_[" << r_wd << "]: " << std::hex << wd << std::dec << endl;
}
assert(0 != col_sums[c]);
}
}
}