本文整理汇总了C++中VecStr::reserve方法的典型用法代码示例。如果您正苦于以下问题:C++ VecStr::reserve方法的具体用法?C++ VecStr::reserve怎么用?C++ VecStr::reserve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VecStr
的用法示例。
在下文中一共展示了VecStr::reserve方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: longToRagged
int longToRagged(const SEXP& icd9df, VecVecStr& ragged, VecStr& visitIds,
const std::string visitId, const std::string icd9Field =
"icd9", bool aggregate = true) {
#ifdef ICD9_VALGRIND
CALLGRIND_START_INSTRUMENTATION;
#endif
SEXP icds = PROTECT(getRListOrDfElement(icd9df, icd9Field.c_str()));
SEXP vsexp = PROTECT(getRListOrDfElement(icd9df, visitId.c_str()));
const int approx_cmb_per_visit = 15; // just an estimate. Prob best to overestimate.
int vlen = Rf_length(icds);
visitIds.reserve(vlen / approx_cmb_per_visit);
ragged.reserve(vlen / approx_cmb_per_visit);
int max_per_pt = 1;
if (TYPEOF(vsexp) != STRSXP)
Rcpp::stop("need string input to longToRagged\n");
#ifdef ICD9_DEBUG
Rcpp::Rcout << "longToRagged SEXP is STR\n";
#endif
const char* lastVisitId = "";
for (int i = 0; i < vlen; ++i) {
// always STRING? may get numeric, integer, factor? Can always handle this on R side
const char* icd = CHAR(STRING_ELT(icds, i));
const char* vi = CHAR(STRING_ELT(vsexp, i));
if (strcmp(lastVisitId, vi) != 0
&& (!aggregate
|| std::find(visitIds.rbegin(), visitIds.rend(), vi)
== visitIds.rend())) {
VecStr vcodes;
vcodes.reserve(approx_cmb_per_visit); // estimate of number of codes per patient.
vcodes.push_back(icd); // new vector of ICD codes with this first item
ragged.push_back(vcodes); // and add that vector to the intermediate structure
visitIds.push_back(vi);
} else {
#ifdef ICD9_DEBUG
if (ragged.size()==0) {
Rcout << "ragged size is ZERO! aborting\n";
break;
}
#endif
ragged[ragged.size() - 1].push_back(icd); // augment vec for current visit and N/V/E type // EXPENSIVE.
int len = ragged[ragged.size() - 1].size(); // get new count of cmb for one patient
if (len > max_per_pt)
max_per_pt = len;
}
#ifdef ICD9_DEBUG_TRACE
Rcout << "ragged size is " << ragged.size() << "\n";
#endif
lastVisitId = vi;
} // end loop through all visit-code input data
#ifdef ICD9_VALGRIND
CALLGRIND_STOP_INSTRUMENTATION;
// CALLGRIND_DUMP_STATS;
#endif
UNPROTECT(2); // do sooner if possible?
return max_per_pt;
}
示例2: extractCols
VecStr TableReader::extractCols(const VecStr & row, const VecStr & cols) const{
VecStr ret;
ret.reserve(cols.size());
for(const auto & col : cols){
ret.emplace_back(row[header_.getColPos(col)]);
}
return ret;
}
示例3: fastPermuteVectorOneLength
const VecStr fastPermuteVectorOneLength(std::string vec) {
VecStr ans;
int numOfPermutes = Factorial((int)vec.size());
ans.reserve(numOfPermutes);
do {
ans.push_back(vec);
} while (std::next_permutation(vec.begin(), vec.end()));
return ans;
}
示例4: numVecToVecStr
VecStr numVecToVecStr(const std::vector<T>& nums) {
VecStr ans;
ans.reserve(nums.size());
// std::generate_n(ans.begin(), nums.size(), [](const T & num) {return
// estd::to_string(num);});
for (const auto& num : nums) {
ans.emplace_back(estd::to_string(num));
}
return ans;
}
示例5: toVecStr
VecStr toVecStr(const T&... items) {
VecStr ret;
ret.reserve(sizeof...(items));
toVecStrAdd(ret, items...);
return ret;
}