-
Notifications
You must be signed in to change notification settings - Fork 0
/
a6.hpp
38 lines (32 loc) · 954 Bytes
/
a6.hpp
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
/**
* a6.cpp
* Name: Supratik Neupane
* Person number: 50160008
*
*
*/
#ifndef A6_STRINGSTORE_HPP
#define A6_STRINGSTORE_HPP
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <unordered_map>
class StringStore {
// an unordered_map to store the pairs of string and frequency
private: std::unordered_map<std::string, size_t> store;
//a comparator to help sort the strings in non-decreasing order of frequency
class FrequencyComparator {
public:
bool operator()(const std::pair<std::string, size_t>& lhs, const std::pair<std::string, size_t>& rhs) {
return lhs.second<rhs.second;
}
};
public:
void insert(const std::string& str);
size_t getFrequency(const std::string& str) const;
bool removeString(const std::string& str);
std::pair<std::string, size_t> getMaxFrequency() const;
std::vector<std::pair<std::string, size_t>> getTopKFrequency(size_t k) const;
};
#endif //A6_STRINGSTORE_HPP