本文整理汇总了C++中Bitset::set方法的典型用法代码示例。如果您正苦于以下问题:C++ Bitset::set方法的具体用法?C++ Bitset::set怎么用?C++ Bitset::set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Bitset
的用法示例。
在下文中一共展示了Bitset::set方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: IndexForChar
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 ) );
}
示例2: range
Bitset range(int l, int r) {
Bitset ret;
for (int i = l; i < r; ++i) {
ret.set(i);
}
return ret;
}
示例3:
TEST(tinybitset_unittest, test_bitset_boundrytest) {
Bitset bitset;
bool res = bitset.set(-1);
EXPECT_EQ(0,res);
res = bitset.set(128);
EXPECT_EQ(0,res);
res = bitset.set(0);
EXPECT_EQ(1,res);
res = bitset.set(127);
EXPECT_EQ(1,res);
res = bitset.get(-1);
EXPECT_EQ(0,res);
res = bitset.get(128);
EXPECT_EQ(0,res);
res = bitset.get(0);
EXPECT_EQ(1,res);
res = bitset.get(127);
EXPECT_EQ(1,res);
}
示例4:
TEST(Bitset, set)
{
Bitset<2> bs;
ASSERT_EQ(bs.size(), 2);
EXPECT_FALSE(bs[0]);
EXPECT_FALSE(bs[1]);
bs.set(0, true);
EXPECT_TRUE(bs[0]);
bs.set(0, false);
EXPECT_FALSE(bs[0]);
bs.set(1, true);
EXPECT_TRUE(bs[1]);
Bitset<82> bs2;
ASSERT_EQ(bs2.size(), 82);
EXPECT_FALSE(bs2[70]);
bs2.set(70, true);
EXPECT_TRUE(bs2[70]);
}
示例5: main
int main() {
map<string, pair<int, int> > var;
stack<Bitset> val;
char buf[80], *p;
int n, x, y;
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%s%d%d", buf, &x, &y);
var[buf] = make_pair(x, y + 1);
}
scanf("%d", &n);
for (int i = 0; i < n; ++i) {
scanf("%s", buf);
x = strtol(buf, &p, 10);
if (*p == '\0') {
val.push(range(x, x + 1));
} else if (strchr("+-*/", buf[0]) == NULL) {
pair<int, int> snd = var[buf];
val.push(range(snd.first, snd.second));
} else {
Bitset rhs = val.top();
val.pop();
Bitset lhs = val.top();
val.pop();
if (buf[0] == '/' && rhs[0]) {
puts("error");
return 0;
} else {
Bitset ret;
for (int i = 0; i < (int)lhs.size(); ++i) {
if (!lhs[i]) {
continue;
}
for (int j = 0; j < (int)rhs.size(); ++j) {
if (!rhs[j]) {
continue;
}
ret.set(eval(i, j, buf[0]));
}
}
val.push(ret);
}
}
}
puts("correct");
return 0;
}
示例6: 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