5 #include <unordered_map> 9 #include <glog/logging.h> 17 std::unordered_map<T, size_t> map;
27 size_t prev_value = map[item];
28 map[item] = prev_value + 1;
48 std::vector<std::pair<T, size_t>> v(map.begin(), map.end());
49 std::sort(v.begin(), v.end(), [] (
50 std::pair<T, size_t> a, std::pair<T, size_t> b
53 if (a.second != b.second) {
54 return a.second > b.second;
56 return a.first < b.first;
Contains the text compression and encoding framework.
std::unordered_map< T, size_t > ranking_t
std::vector< std::pair< T, size_t > > getSorted()
Return a list of value-count pairs, sorted with the most-seen first.
A data structure for counting occurences of values of a given type T.
size_t getCount(const T &item)
Get the count associated with a value.
size_t getNumItems()
Return how many differnt values have been seen so far.
void increase(const T &item)
Increase the counter for the passed value by one, setting it to 1 if it was not yet seen...
ranking_t createRanking(size_t num=SIZE_MAX)
Return a map of the num-most common values, keyed by their common-ness, with map[0] being hte most co...
void setCount(const T &item, size_t count)
Set the count of an item to a specific value.