本文整理汇总了C++中UIntVector::resize方法的典型用法代码示例。如果您正苦于以下问题:C++ UIntVector::resize方法的具体用法?C++ UIntVector::resize怎么用?C++ UIntVector::resize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UIntVector
的用法示例。
在下文中一共展示了UIntVector::resize方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: calc_pivot
char WaveletTree::calc_pivot(const std::string& alph, const CharIntMap& counts) {
UIntVector scores;
scores.resize(alph.size(), 0);
for (std::size_t i = 0; i < alph.size(); i++) {
// calc the number of 0s and 1s
UInt sum_before = 0;
UInt sum_after = 0;
for (std::size_t j = 0; j < i; j++) {
// operator[] can't be used in const map, so I had to use
// find to get iterator
CharIntMap::const_iterator elem = counts.find(alph[j]);
if (elem == counts.end())
throw std::runtime_error("counts has missing key");
sum_before += elem->second;
}
for (std::size_t j = i; j < alph.size(); j++) {
CharIntMap::const_iterator elem = counts.find(alph[j]);
if (elem == counts.end())
throw std::runtime_error("counts has missing key");
sum_after += elem->second;
}
// diff between numbers of 0s and 1s
scores[i] = abs(sum_before - sum_after);
// if current score is worse than prev, than prev is the best,
// continuing will only give worse scores
if (i > 0 && scores[i] > scores[i-1])
return alph[i-1];
}
return alph[alph.size() - 1];
}