本文整理汇总了C++中array_t::clear方法的典型用法代码示例。如果您正苦于以下问题:C++ array_t::clear方法的具体用法?C++ array_t::clear怎么用?C++ array_t::clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类array_t
的用法示例。
在下文中一共展示了array_t::clear方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: if
void ibis::array_t<T>::stableSort(array_t<uint32_t>& ind) const {
if (size() > 2) {
if (size() > 0xFFFFFFFFUL) {
ind.clear();
return;
}
array_t<T> tmp1, tmp2;
array_t<uint32_t> itmp;
tmp1.deepCopy(*this);
ibis::array_t<T>::stableSort(tmp1, ind, tmp2, itmp);
}
else if (size() == 2) {
ind.resize(2);
if (m_begin[1] < m_begin[0]) {
const T tmp = m_begin[1];
m_begin[1] = m_begin[0];
m_begin[0] = tmp;
ind[0] = 1;
ind[1] = 0;
}
else {
ind[0] = 0;
ind[1] = 1;
}
}
else if (size() == 1) {
ind.resize(1);
ind[0] = 0;
}
else {
ind.clear();
}
} // stableSort
示例2: size
void ibis::array_t<T>::sort(array_t<uint32_t>& ind) const {
const size_t na = size();
size_t ni = ind.size();
bool keepind = (ni > 0);
for (size_t j = 0; keepind && j < ni; ++ j)
keepind = (ind[j] < na);
if (! keepind) { // initalize ind to [0:na-1]
ni = na;
ind.resize(na);
for (size_t i = 0; i < na; ++i)
ind[i] = i;
}
if (ni < 2) { // no need to sort
return;
}
if (ni > 0xFFFFFFFFUL) { // do not support arrays of this size?
ind.clear();
return;
}
// call qsort to do the actual work
qsort(ind, 0, ni);
#if DEBUG+0 > 1 || _DEBUG+0 > 1
ibis::util::logger lg(4);
lg.buffer() << "DEBUG -- sort(ind[" << ni << "])";
for (size_t i = 0; i < ni; ++i)
lg.buffer() << "\nind[" << i << "]=" << ind[i] << "\t"
<< m_begin[ind[i]];
#endif
} // sort
示例3: fseek
/// Write the dictionary one keyword at a time. This version requires on
/// write call on each keyword, which can be time consuming when there are
/// many keywords.
int ibis::dictionary::writeKeys(FILE *fptr, uint32_t nkeys,
array_t<uint64_t> &pos,
array_t<uint32_t> &qos) const {
int ierr = fseek(fptr, 8*(nkeys+1)+4*nkeys, SEEK_CUR);
long int tmp = ftell(fptr);
pos.clear();
qos.clear();
pos.push_back(tmp);
for (uint32_t j = 0; j < raw_.size(); ++ j) {
if (raw_[j] != 0) {
const int len = 1 + std::strlen(raw_[j]);
ierr = fwrite(raw_[j], 1, len, fptr);
LOGGER(ierr != len && ibis::gVerbose > 1)
<< "Warning -- dictionary::writeKeys failed to write key["
<< j << "]; expected fwrite to return " << len
<< ", but got " << ierr;
tmp += len;
qos.push_back(j);
pos.push_back(tmp);
}
}
tmp = 0;
// go back to write the offsets/positions
ierr = fseek(fptr, 24, SEEK_SET);
LOGGER(ierr != 0 && ibis::gVerbose > 1)
<< "Warning -- dictionary::writeKeys failed to seek to offset 24 "
"to write the offsets";
ierr = fwrite(pos.begin(), sizeof(uint64_t), nkeys+1, fptr);
LOGGER(ierr != (int)(nkeys+1) && ibis::gVerbose > 1)
<< "Warning -- dictionary::writeKeys failed to write the offsets, "
"expected fwrite to return " << nkeys+1 << ", but got " << ierr;
tmp -= 7 * (ierr != (int)(nkeys+1));
ierr = fwrite(qos.begin(), sizeof(uint32_t), nkeys, fptr);
LOGGER(ierr != (int)(nkeys) && ibis::gVerbose > 1)
<< "Warning -- dictionary::writeKeys failed to write the keys, "
"expected fwrite to return " << nkeys << ", but got " << ierr;
tmp -= 8 * (ierr != (int)(nkeys));
return tmp;
} // ibis::dictionary::writeKeys
示例4: test_expression
bool test_expression(const lexer_t& lexer,
const expression_parser_rules_t& parser_rules,
array_t& new_parsed_expression,
adobe_parser_t adobe_parse,
const std::string& expression)
{
std::cout << "expression: \"" << expression << "\"\n";
array_t original_parsed_expression;
bool original_parse_failed = false;
try {
original_parsed_expression = adobe_parse(expression);
} catch (const stream_error_t&) {
original_parse_failed = true;
}
if (original_parse_failed)
std::cout << "original: <parse failure>\n";
else
std::cout << "original: " << original_parsed_expression << "\n";
using boost::spirit::qi::phrase_parse;
text_iterator_t it(expression.begin());
detail::s_text_it = ⁢
detail::s_begin = it;
detail::s_end = text_iterator_t(expression.end());
detail::s_filename = "test_expression";
token_iterator_t iter = lexer.begin(it, detail::s_end);
token_iterator_t end = lexer.end();
bool new_parse_failed =
!phrase_parse(iter,
end,
parser_rules.expression(boost::phoenix::ref(new_parsed_expression)),
boost::spirit::qi::in_state("WS")[lexer.self]);
if (new_parse_failed)
std::cout << "new: <parse failure>\n";
else
std::cout << "new: " << new_parsed_expression << "\n";
bool pass =
original_parse_failed && new_parse_failed ||
new_parsed_expression == original_parsed_expression;
std::cout << (pass ? "PASS" : "FAIL") << "\n";
if (!pass) {
std::cout << "original (verbose):\n";
verbose_dump(original_parsed_expression);
std::cout << "new (verbose):\n";
verbose_dump(new_parsed_expression);
}
std::cout << "\n";
new_parsed_expression.clear();
return pass;
}