1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| #include <iostream> #include <vector> #include <string> #include <map> #include <unordered_map> #include <queue> using namespace std;
class Node { public: string str; int times; Node(string s, int t) : str(s), times(t) {} Node() : str(""), times(0) {} bool operator==(const Node &n) const { return this->str == n.str && this->times == n.times; } };
template <typename T> void hashCombine(size_t &seed, const T &arg) { seed ^= hash<T>()(arg) + 0x9e3779b9 + (seed << 6) + (seed >> 2); } template <typename T> void hashValue(size_t &seed, const T &arg) { hashCombine(seed, arg); } template <typename T1, typename... T2> void hashValue(size_t &seed, const T1 &arg, const T2 &...args) { hashCombine(seed, arg); hashValue(seed, args...); } template <typename... T> size_t hashValue(const T &...args) { size_t seed = 0; hashValue(seed, args...); return seed; } class Hasher { public: size_t operator()(const Node &n) const { return hashValue(n.str, n.times); } };
class TopKRecord { public: TopKRecord(int size) { heap.resize(size); index = 0; }
private: vector<Node> heap; int index; unordered_map<string, Node> strNodeMap; unordered_map<Node, int, Hasher> nodeIndexMap; };
int main() { return 0; }
|