#include #include #include #include #include #include #include "linecount.h" #include "readlog.h" bool person::operator<(const struct person &other) const { return this->nick < other.nick; } bool person::operator!=(const struct person &other) const { return this->nick != other.nick; } bool personcmp(struct person a, struct person b) { return a.linecount > b.linecount; } // Sorted linecounts, most lines first void get_linecounts(std::vector &sorted, const std::vector &lines) { std::map linecounts; std::vector::const_iterator iter; for (iter = lines.begin(); iter != lines.end(); iter++) { if (linecounts.find(iter->nick) == linecounts.end()) { // New nick linecounts[iter->nick].nick = iter->nick; linecounts[iter->nick].linecount = 0; linecounts[iter->nick].status = normal; } linecounts[iter->nick].linecount++; if (iter->status > linecounts[iter->nick].status) linecounts[iter->nick].status = iter->status; } std::map::const_iterator iter2; for (iter2 = linecounts.begin(); iter2 != linecounts.end(); iter2++) { sorted.push_back(iter2->second); } std::sort(sorted.begin(), sorted.end(), personcmp); } void select_to_set(std::set &dest, const std::vector &linecounts, int nickcount) { std::vector::const_iterator iter; for (iter = linecounts.begin(); iter != linecounts.begin() + nickcount && iter != linecounts.end(); iter++) { dest.insert(*iter); } }