本文整理汇总了C++中BitArray::setbit方法的典型用法代码示例。如果您正苦于以下问题:C++ BitArray::setbit方法的具体用法?C++ BitArray::setbit怎么用?C++ BitArray::setbit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitArray
的用法示例。
在下文中一共展示了BitArray::setbit方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: test_temp
void test_temp(int len) {
const std::vector<bool>& vec = bits_imbal(len);
BitArray v;
v = BitArrayBuilder::create(vec.size());
v.fillzero();
for (unsigned int i = 0; i < vec.size(); i++) {
v.setbit(i, vec[i]);
}
Rank6p t;
//Rank6pBuilder bd;
Rank6pBuilder::build(v, &t);
Rank6pHintSel rhs;
rhs.init(v);
unsigned int onecnt = 0;
for (unsigned int i = 0; i < vec.size(); ++i)
if (vec[i]) onecnt++;
int last = -1;
for (unsigned int i = 0; i < onecnt; ++i) {
int pos = rhs.select(i);
//int pos2 = t.select(i);
if (pos >= vec.size() || !vec[pos] || pos <= last) {
cout << "select " << i << " " << rhs.select(i) << endl;
if (i > 0) rhs.select(i-1);
ASSERT(vec[pos] == true);
}
ASSERT(pos > last);
last = pos;
}
}
示例2: find_pioneers
BitArray find_pioneers(const BitArrayInterface* bp, size_t blksize) {
std::vector<uint64_t> v = find_pioneers_v(bp, blksize);
BitArray ret = BitArrayBuilder::create(bp->length());
ret.fillzero();
for (int i = 0; i < v.size(); i++)
ret.setbit(v[i], true);
return ret;
}
示例3: test_rank
void test_rank(const std::vector<bool>& vec) {
vector<int> ranks(vec.size() + 1);
ranks[0] = 0;
for (unsigned int i = 1; i <= vec.size(); i++)
if (vec[i-1]) ranks[i] = ranks[i-1] + 1;
else ranks[i] = ranks[i-1];
BitArray v;
v = BitArrayBuilder::create(vec.size());
//v.fillzero();
for (unsigned int i = 0; i < vec.size(); i++) {
v.setbit(i, vec[i]);
}
for (unsigned int i = 0; i < vec.size(); i++) {
ASSERT(vec[i] == v.bit(i));
}
RankSelect r;
RankSelect::BuilderTp::build(v, &r);
for (unsigned int i = 0; i < vec.size(); ++i)
ASSERT_EQ(vec[i], r.access(i));
for (int i = 0; i <= vec.size(); ++i) {
if (ranks[i] != r.rank(i)) {
cout << "rank " << i << " " << ranks[i] << " " << r.rank(i) << endl;
ASSERT_EQ(ranks[i], r.rank(i));
}
}
unsigned int onecnt = 0;
for (unsigned int i = 0; i < vec.size(); ++i)
if (vec[i]) onecnt++;
int last = -1;
for (unsigned int i = 0; i < onecnt; ++i) {
int pos = r.select(i);
ASSERT_EQ(i, r.rank(pos));
ASSERT_EQ(i + 1, r.rank(pos + 1));
if (pos >= vec.size() || !vec[pos] || pos <= last) {
cout << "select " << i << " " << r.select(i) << endl;
if (i > 0) r.select(i-1);
ASSERT_EQ(true, vec[pos]);
}
ASSERT(pos > last);
last = pos;
}
last = -1;
for (unsigned int i = 0; i < vec.size() - onecnt; ++i) {
int pos = r.selectzero(i);
ASSERT_EQ(i, r.rankzero(pos)) << "pos =" << pos << " i =" << i << " len=" << r.length() << endl;
ASSERT_EQ(i + 1, r.rankzero(pos + 1));
ASSERT(pos < vec.size() && vec[pos] == false);
ASSERT(pos > last);
last = pos;
}
}