本文整理汇总了C++中BitArray::size方法的典型用法代码示例。如果您正苦于以下问题:C++ BitArray::size方法的具体用法?C++ BitArray::size怎么用?C++ BitArray::size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BitArray
的用法示例。
在下文中一共展示了BitArray::size方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ResultPoint
static RSS::FinderPattern
ParseFoundFinderPattern(const BitArray& row, int rowNumber, bool right, BitArray::Range range, FinderCounters& finderCounters)
{
if (!range || range.begin == row.begin())
return {};
// Actually we found elements 2-5 -> Locate element 1
auto i = std::find(BitArray::ReverseIterator(range.begin), row.rend(), *range.begin);
int firstCounter = range.begin - i.base();
range.begin = i.base();
// Make 'counters' hold 1-4
std::copy_backward(finderCounters.begin(), finderCounters.end() - 1, finderCounters.end());
finderCounters[0] = firstCounter;
int value = RSS::ReaderHelper::ParseFinderValue(finderCounters, FINDER_PATTERNS);
if (value < 0)
return {};
int start = range.begin - row.begin();
int end = range.end - row.begin();
if (right) {
// row is actually reversed
start = row.size() - 1 - start;
end = row.size() - 1 - end;
}
return {value,
range.begin - row.begin(),
range.end - row.begin(),
{ResultPoint(start, rowNumber), ResultPoint(end, rowNumber)}};
}
示例2: string
static std::string
DecodeAI01393x(const BitArray& bits)
{
static const int HEADER_SIZE = 5 + 1 + 2;
static const int LAST_DIGIT_SIZE = 2;
static const int FIRST_THREE_DIGITS_SIZE = 10;
if (bits.size() < HEADER_SIZE + AI01_GTIN_SIZE) {
return std::string();
}
std::string buffer;
AI01EncodeCompressedGtin(buffer, bits, HEADER_SIZE);
int lastAIdigit = GenericAppIdDecoder::ExtractNumeric(bits, HEADER_SIZE + AI01_GTIN_SIZE, LAST_DIGIT_SIZE);
buffer.append("(393");
buffer.append(std::to_string(lastAIdigit));
buffer.push_back(')');
int firstThreeDigits = GenericAppIdDecoder::ExtractNumeric(bits, HEADER_SIZE + AI01_GTIN_SIZE + LAST_DIGIT_SIZE, FIRST_THREE_DIGITS_SIZE);
if (firstThreeDigits / 100 == 0) {
buffer.push_back('0');
}
if (firstThreeDigits / 10 == 0) {
buffer.push_back('0');
}
buffer.append(std::to_string(firstThreeDigits));
if (StatusIsOK(GenericAppIdDecoder::DecodeGeneralPurposeField(bits, HEADER_SIZE + AI01_GTIN_SIZE + LAST_DIGIT_SIZE + FIRST_THREE_DIGITS_SIZE, buffer))) {
return buffer;
}
return std::string();
}
示例3: encode
BitArray GammaEncoder::encode(unsigned int num) const{
BitArray numBinaryRemaining = getBinaryWithoutHighestOne(num);
return unary.encode(numBinaryRemaining.size() + 1) + numBinaryRemaining;
}
示例4: main
// Test program
int main() {
// Test exceptions
BitArray<> b;
throw_(b[0],logic_error);
throw_(b.toggle(0),logic_error);
const BitArray<> b1{b}; // Test copy constructor
throw_(b1[0],logic_error);
// Test empty Bitarray properties
test_(b.size() == 0);
test_(b.count() == 0);
test_(b.capacity() == 0);
test_(!b.any());
// Validate construction and to_string()
BitArray<> b2{5};
test_(b2.size() == 5);
for (size_t i = 0; i < 5; ++i) {
test_(!b2[i]);
}
test_(b2.to_string() == "00000");
// Test copy, assign, equality, and from_string
BitArray<> b3{b2};
test_(b2 == b3);
test_(b != b2);
test_(!b3[2]);
b3[2] = 1;
test_(b3[2]);
test_(b2 != b3);
test_(b2.to_string() == "00000");
b = b2;
test_(b.to_string() == "00000");
// Test move operations
BitArray<> b4{move(b3)};
test_(b4[2]);
BitArray<> b4b;
b4b = move(b4);
test_(b4b[2]);
// Test bit ops
BitArray<> x{"011010110"}; // Also tests string constructor
test_(x.count() == 5);
test_(x.any());
test_((x << 6).to_string() == "110000000");
test_((x >> 6).to_string() == "000000011");
test_((x <<= 3).to_string() == "010110000");
test_((x >>= 3).to_string() == "000010110");
BitArray<> y{~x};
nothrow_(x.toggle());
test_(x == y);
test_(x.to_string() == "111101001");
b = BitArray<> {};
test_(!b.any());
b += 1;
b += 0;
b += 1;
test_(b.to_string() == "101");
test_(b.any());
b2 = BitArray<> {"10101011"};
test_(b2.count() == 5);
b2.toggle();
test_(b2.to_string() == "01010100");
b2.erase(3);
test_(b2.to_string() == "0100100");
b2.erase(b2.size() - 1);
test_(b2.to_string() == "010010");
b2.erase(1,4);
test_(b2.to_string() == "00");
b2.insert(1,1);
test_(b2.to_string() == "010");
b2.insert(1,0);
test_(b2.to_string() == "0010");
b2 += b;
test_(b2.to_string() == "0010101");
b2.insert(3, b);
test_(b2.to_string() == "0011010101");
ostringstream os;
os << "101" << 'a' << "0101";
istringstream is{os.str()};
b3 = BitArray<> {};
is >> b3;
test_(b3.to_string() == "101");
is.get();
is >> b3;
test_(b3.to_string() == "0101");
os.str("");
os << 'a';
istringstream is2{os.str()};
is2 >> b3;
test_(!is2);
test_(b3.to_string() == "0101");
BitArray<> b5{"11111111111111111111111111000000000000000000000000000011"};
test_(b5.slice(23,10) == BitArray<>("1110000000"));
//.........这里部分代码省略.........