本文整理汇总了C++中Bitset类的典型用法代码示例。如果您正苦于以下问题:C++ Bitset类的具体用法?C++ Bitset怎么用?C++ Bitset使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Bitset类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: testMultiplicationSquares
void testMultiplicationSquares(std::size_t noBits, DynamicElementStorageType lhsStorage, DynamicElementStorageType rhsStorage)
{
Bitset activeBits;
for(std::size_t i = 0; i < noBits; ++i)
activeBits[std::rand() & MAX_K_VALUE] = true;
Element lhs(activeBits, lhsStorage);
// get a non-zero value
Z2k value;
while(value.getValue() == 0)
value = Z2k( rand() & activeBits.to_ulong() );
// get a coeff
GaloisField coeff( rand() & 255 );
lhs.setCoefficient(value, coeff);
lhs.setCoefficient(Z2k(), coeff);
Element rhs(lhs, rhsStorage);
Element prod;
algebra.multiply(lhs, rhs, prod);
BOOST_CHECK_EQUAL(prod.isZero(), true);
}
示例2: TEST
TEST(tinybitset_unittest, test_bitset_init) {
Bitset bitset;
bool res = bitset.empty();
EXPECT_EQ(true, res);
vector<int> bitones = bitset.getbitones();
EXPECT_EQ(0,bitones.size());
}
示例3: GetFlappingBuffer
void Checkable::UpdateFlappingStatus(bool stateChange)
{
Bitset<unsigned long> stateChangeBuf = GetFlappingBuffer();
int oldestIndex = GetFlappingIndex();
stateChangeBuf.Modify(oldestIndex, stateChange);
oldestIndex = (oldestIndex + 1) % 20;
double stateChanges = 0;
/* Iterate over our state array and compute a weighted total */
for (int i = 0; i < 20; i++) {
if (stateChangeBuf.Get((oldestIndex + i) % 20))
stateChanges += 0.8 + (0.02 * i);
}
double flappingValue = 100.0 * stateChanges / 20.0;
bool flapping;
if (GetFlapping())
flapping = flappingValue > GetFlappingThresholdLow();
else
flapping = flappingValue > GetFlappingThresholdHigh();
SetFlappingBuffer(stateChangeBuf.GetValue());
SetFlappingIndex(oldestIndex);
SetFlappingCurrent(flappingValue);
SetFlapping(flapping, true);
if (flapping != GetFlapping())
SetFlappingLastChange(Utility::GetTime());
}
示例4: range
Bitset range(int l, int r) {
Bitset ret;
for (int i = l; i < r; ++i) {
ret.set(i);
}
return ret;
}
示例5: TEST
TEST(Bitset, flipFirstBitOfSecondNum)
{
Bitset<100> bs;
EXPECT_FALSE(bs.test(0));
bs.flip(64);
EXPECT_TRUE(bs.test(64));
// The first bit was flipped because indexFromBits(64) returned 0 instead of 1 earlier!
EXPECT_FALSE(bs.test(0));
}
示例6: write_bitset
void FileSystemApi::write_bitset(DBC &conf, Bitset &b) {
assert(file.is_open());
assert(file.good());
file.seekp(get_bitset_offset(conf), std::ios_base::beg);
file.write(b.as_bytes(), b.num_blocks());
file.seekg(get_bitset_offset(conf), std::ios_base::beg);
char *buff = new char[get_bitset_size(conf)];
file.read(buff, get_bitset_size(conf));
delete[] buff;
}
示例7: load_inst_constrain
static void load_inst_constrain(Instance * inst,Bitset * original_bitset) {
if(original_bitset){
inst->external_lexicon_match_state.push_back((*original_bitset));
}
else{
Bitset bitset;
bitset.allsetones();
inst->external_lexicon_match_state.push_back(bitset);
}
}//end func load_inst_constrain
示例8: TEST
TEST( LetterBitsetFromStringTest, Basic ) {
Bitset expected;
expected.set( IndexForChar( 'a' ) );
expected.set( IndexForChar( 'o' ) );
expected.set( IndexForChar( 'c' ) );
expected.set( IndexForChar( 'f' ) );
expected.set( IndexForChar( 'b' ) );
std::string text = "abcfoof";
EXPECT_EQ( expected, LetterBitsetFromString( text ) );
}
示例9: lock
uint32_t lock(T * keys){
int i;
uint32_t unlockVar;
Bitset b;
b.Resize(1000);
for(i=0;i<thread_num;i++)
{
b.Set(keys[i]);
}
unlockVar = m.Lock(b);
return unlockVar;
}
示例10: lock
uint32_t lock(int key1,int key2){
int i;
uint32_t unlockVar;
Bitset b;
b.Resize(1000);
b.Set(key1);
b.Set(key2);
unlockVar = m.Lock(b);
return unlockVar;
}
示例11: ilog2_bitset_trivial
inline int ilog2_bitset_trivial(Bitset v)
{
int ret = 0;
for( ; v.any(); v >>= 1 )
++ret;
return ret - 1;
}
示例12: read_bitset
void FileSystemApi::read_bitset(DBC &conf, Bitset &b) {
assert(file.good());
file.seekg(get_bitset_offset(conf), std::ios_base::beg);
char *buff = new char[get_bitset_size(conf)];
file.read(buff, get_bitset_size(conf));
b.from_bytes(get_bitset_size(conf), buff);
delete[] buff;
}
示例13: load_model_constrain
static void load_model_constrain(Model * model , const char * lexicon_file = NULL) {
if (NULL != lexicon_file) {
std::ifstream lfs(lexicon_file);
if (lfs) {
std::string buffer;
std::vector<std::string> key_values;
int key_values_size;
std::string key;
int value;
Bitset * original_bitset;
while (std::getline(lfs, buffer)) {
buffer = ltp::strutils::chomp(buffer);
if (buffer.size() == 0) {
continue;
}
Bitset values;
key_values = ltp::strutils::split(buffer);
key_values_size = key_values.size();
if(key_values_size == 0 || key_values_size == 1) {
continue;
}
key = ltp::strutils::chartypes::sbc2dbc_x(key_values[0]);
for(int i=1;i<key_values_size;i++){
value = model->labels.index(key_values[i]);
if (value != -1){
if(!(values.set(value))) {
WARNING_LOG("Tag named %s for word %s add external lexicon error.",key_values[i].c_str(),key_values[0].c_str());
}
}
else {
WARNING_LOG("Tag named %s for word %s is not existed in LTP labels set.",key_values[i].c_str(),key_values[0].c_str());
}
}
if(!values.empty()) {
original_bitset = model->external_lexicon.get(key.c_str());
if(original_bitset){
original_bitset->merge(values);
}
else{
model->external_lexicon.set(key.c_str(),values);
}
}
}
}
}
}//end func load_model_constrain
示例14: find
int find(long long a, long long b) {
fibs[0] = 1;
fibs[1] = 2;
for (int i = 2; i < N; ++ i) {
fibs[i] = fibs[i - 1] + fibs[i - 2];
}
memory[1] = 0;
Bitset mask = solve(b + 1) ^ solve(a);
int result = 0;
for (int i = N - 1; i >= 0; -- i) {
(result *= 2) %= MOD;
if (mask.test(i)) {
(result += 1) %= MOD;
}
}
return result;
}
示例15: while
Bitset* Journal::getBitsetbyKey(unsigned key, uint64_t start_tid, uint64_t end_tid)
{
DArray<unsigned>* offsets = key_htable.getHashRecords(key, start_tid, end_tid);
unsigned start_offset, end_offset, i;
if(offsets == NULL)
return NULL;
#if TID_HASHTABLE == 1
while((start_offset = tidSearchRecord(start_tid)) == -1) // psakse se pio index tou Journal tha ksekinisw na psaxnw
start_tid += 1; // an den yparxei to tid pou mou dwse san start psakse to epomeno
while((end_offset = tidSearchRecord(end_tid)) == -1)
end_tid -= 1;
#else
while((start_offset = searchRecord(start_tid)) == -1) // psakse se pio index tou Journal tha ksekinisw na psaxnw
start_tid += 1; // an den yparxei to tid pou mou dwse san start psakse to epomeno
while((end_offset = searchRecord(end_tid)) == -1)
end_tid -= 1;
#endif
int rsize = Records->size();
for (i = end_offset; i < rsize; i++)
{
uint64_t tid = (Records->get(i))->getTransactionId();
if (tid > end_tid) // an exw kseperasei to end_tid
break;
}
end_offset = i;
Bitset* bit = new Bitset((end_offset - start_offset)/8 + 1);
for(i = 0; i < offsets->size(); i++)
{
bit->setBitsetValue(offsets->get(i) - start_offset);
}
delete offsets;
return bit;
}