本文整理汇总了C++中IndexVector::sort方法的典型用法代码示例。如果您正苦于以下问题:C++ IndexVector::sort方法的具体用法?C++ IndexVector::sort怎么用?C++ IndexVector::sort使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IndexVector
的用法示例。
在下文中一共展示了IndexVector::sort方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Sort
// Sort elements and return sort index mapping.
bool NgramVector::Sort(const VocabVector &vocabMap,
const IndexVector &boNgramMap,
IndexVector &ngramMap) {
// Update word and hist indices.
for (size_t i = 0; i < size(); ++i) {
_words[i] = vocabMap[_words[i]];
_hists[i] = boNgramMap[_hists[i]];
}
// Sort indices.
NgramIndexCompare compare(*this);
IndexVector sortIndices = Range(0, size());
if (!sortIndices.sort(compare)) {
ngramMap = Range(size());
return false;
}
// Apply ordered indices to values.
// Build sort mapping that maps old to new indices.
VocabVector newWords(_words.length());
IndexVector newHists(_hists.length());
ngramMap.reset(size());
for (NgramIndex i = 0; i < (NgramIndex)size(); i++) {
newWords[i] = _words[sortIndices[i]];
newHists[i] = _hists[sortIndices[i]];
ngramMap[sortIndices[i]] = i;
}
_words.swap(newWords);
_hists.swap(newHists);
// Rebuild index map.
_Reindex(_indices.length());
// Build truncated view into words and hists.
Range r(_length);
_wordsView.attach(_words[r]);
_histsView.attach(_hists[r]);
return true;
}