void Model_Checking::getFrequentUsedNotes(std::vector<wxString> &frequentNotes, int accountID) { frequentNotes.clear(); int max = 20; const auto notes = instance().find(NOTES("", NOT_EQUAL) , accountID > 0 ? ACCOUNTID(accountID) : ACCOUNTID(-1, NOT_EQUAL)); std::map <wxString, int> counterMap; for (const auto& entry : notes) counterMap[entry.NOTES]--; std::map <int, std::vector<wxString> > notesMap; for (const auto& entry : counterMap) notesMap[entry.second].push_back(entry.first); for (auto& v : notesMap) { std::reverse(v.second.begin(), v.second.end()); for (const auto& i : v.second) { frequentNotes.push_back(i); if (frequentNotes.size() >= static_cast<size_t>(max)) break; } if (frequentNotes.size() >= static_cast<size_t>(max)) break; } std::stable_sort(frequentNotes.begin(), frequentNotes.end()); }
void Model_Checking::getFrequentUsedNotes(std::vector<wxString> &frequentNotes, int accountID) { frequentNotes.clear(); size_t max = 20; const auto notes = instance().find(NOTES("", NOT_EQUAL) , accountID > 0 ? ACCOUNTID(accountID) : ACCOUNTID(-1, NOT_EQUAL)); std::map <wxString, int> counterMap; for (const auto& entry : notes) counterMap[entry.NOTES]--; std::priority_queue<std::pair<int, wxString> > q; // largest element to appear as the top for (const auto & kv: counterMap) { q.push(std::make_pair(kv.second, kv.first)); if (q.size() > max) q.pop(); // keep fixed queue as max } while(!q.empty()) { const auto & kv = q.top(); frequentNotes.push_back(kv.second); q.pop(); } }
void Model_Checking::getFrequentUsedNotes(std::vector<wxString> &frequentNotes, int accountID) { frequentNotes.clear(); int max = 20; for (const auto& entry : instance().find(NOTES("", NOT_EQUAL) , accountID > 0 ? ACCOUNTID(accountID) : ACCOUNTID(-1, NOT_EQUAL))) { const wxString& notes = entry.NOTES; if (std::find(frequentNotes.begin(), frequentNotes.end(), notes) == frequentNotes.end()) frequentNotes.push_back(notes); } std::reverse(frequentNotes.begin(), frequentNotes.end()); if (frequentNotes.size() > static_cast<size_t>(max)) frequentNotes.erase(frequentNotes.begin() + max, frequentNotes.end()); std::stable_sort(frequentNotes.begin(), frequentNotes.end()); }