@@ -179,6 +179,9 @@ bool CTokenListDataCategorizerBase::createReverseSearch(int categoryId,
179
179
std::string& part2,
180
180
std::size_t & maxMatchingLength,
181
181
bool & wasCached) {
182
+ wasCached = false ;
183
+ maxMatchingLength = 0 ;
184
+
182
185
if (m_ReverseSearchCreator == nullptr ) {
183
186
LOG_ERROR (<< " Cannot create reverse search - no reverse search creator" );
184
187
@@ -207,8 +210,8 @@ bool CTokenListDataCategorizerBase::createReverseSearch(int categoryId,
207
210
maxMatchingLength = category.maxMatchingStringLen ();
208
211
209
212
// If we can retrieve cached reverse search terms we'll save a lot of time
210
- if ( category.cachedReverseSearch (part1, part2) == true ) {
211
- wasCached = true ;
213
+ wasCached = category.cachedReverseSearch (part1, part2);
214
+ if ( wasCached) {
212
215
return true ;
213
216
}
214
217
@@ -634,27 +637,28 @@ CDataCategorizer::TIntVec CTokenListDataCategorizerBase::usurpedCategories(int c
634
637
}
635
638
auto iter = std::find_if (m_CategoriesByCount.begin (), m_CategoriesByCount.end (),
636
639
[categoryId](const TSizeSizePr& pr) {
637
- return pr.second == static_cast <std::size_t >(categoryId);
640
+ return pr.second ==
641
+ static_cast <std::size_t >(categoryId - 1 );
638
642
});
639
643
if (iter == m_CategoriesByCount.end ()) {
640
644
LOG_WARN (<< " Could not find category definition for category: " << categoryId);
641
645
return usurped;
642
646
}
643
- ++iter;
647
+
644
648
const CTokenListCategory& category{m_Categories[categoryId - 1 ]};
645
- for (; iter != m_CategoriesByCount.end (); ++iter) {
646
- const CTokenListCategory& lessFrequentCategory{
647
- m_Categories[static_cast <int >(iter->second ) - 1 ]};
649
+ for (++iter; iter != m_CategoriesByCount.end (); ++iter) {
650
+ const CTokenListCategory& lessFrequentCategory{m_Categories[iter->second ]};
648
651
bool matchesSearch{category.maxMatchingStringLen () >=
649
652
lessFrequentCategory.maxMatchingStringLen () &&
650
653
category.isMissingCommonTokenWeightZero (
651
654
lessFrequentCategory.commonUniqueTokenIds ()) &&
652
655
category.containsCommonInOrderTokensInOrder (
653
656
lessFrequentCategory.baseTokenIds ())};
654
657
if (matchesSearch) {
655
- usurped.emplace_back (static_cast <int >(iter->second ));
658
+ usurped.emplace_back (1 + static_cast <int >(iter->second ));
656
659
}
657
660
}
661
+ std::sort (usurped.begin (), usurped.end ());
658
662
return usurped;
659
663
}
660
664
0 commit comments