OSDN Git Service

Fix issue #940: Replace slow (2)
[winmerge-jp/winmerge-jp.git] / Src / IntToIntMap.h
1 /**
2  * @file  IntToIntMap.h
3  *
4  * @brief Declaration of Map from int to int, with a couple new methods
5  */
6 #pragma once
7
8 #include <map>
9
10 /**
11  * @brief An int->int map with helper methods for finding largest bin
12  */
13 class IntToIntMap
14 {
15 private:
16         std::map<int, int> m_map;
17 public:
18         void Increment(int key)
19         {
20                 ++m_map[key];
21         }
22         int FindMaxKey() const
23         {
24                 int max=0;
25                 int maxKey=0;
26                 std::map<int, int>::const_iterator pos = m_map.begin();
27                 while (pos != m_map.end())
28                 {
29                         if (pos->second > max)
30                         {
31                                 max = pos->second;
32                                 maxKey = pos->first;
33                         }
34                         ++pos;
35                 }
36                 return maxKey;
37         }
38 };