highlighter application  1.1
HCE project utils : highlighter
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
NotStricktChain.hpp
Go to the documentation of this file.
1 
14 #ifndef NOT_STRICKT_CHAIN_HPP
15 #define NOT_STRICKT_CHAIN_HPP
16 
17 #include <map>
18 
19 //#include "WordPos.hpp"
20 
22 {
23  protected:
24  std::map<unsigned long long, std::pair<unsigned int, unsigned int> > wMap;
25  public:
27  inline void addWord(unsigned long long wordId);
28  inline bool checkOnZerro();
29  inline void setDefaultCounts();
30  inline void decrCount(unsigned long long wordId);
31  inline unsigned int wCount() const;
33 };
34 
35 void NotStricktChain::addWord(unsigned long long wordId)
36 {
37  typename std::map<unsigned long long, std::pair<unsigned int, unsigned int> >::iterator it;
38  if((it = wMap.find(wordId)) == wMap.end())
39  {
40  wMap.insert(std::pair<unsigned long long, std::pair<unsigned int, unsigned int> >(wordId, std::pair<unsigned int, unsigned int>(1, 0)));
41  }
42  else
43  {
44  (*it).second.first++;
45  }
46 }
47 
49 {
50  bool ret = true;
51  typename std::map<unsigned long long, std::pair<unsigned int, unsigned int> >::iterator it;
52  for(it = wMap.begin(); it != wMap.end(); ++it)
53  {
54  if((*it).second.second != 0)
55  {
56  ret = false;
57  break;
58  }
59  }
60  return ret;
61 }
62 
64 {
65  typename std::map<unsigned long long, std::pair<unsigned int, unsigned int> >::iterator it;
66  for(it = wMap.begin(); it != wMap.end(); ++it)
67  {
68  (*it).second.second = (*it).second.first;
69  }
70 }
71 
72 void NotStricktChain::decrCount(unsigned long long wordId)
73 {
74  typename std::map<unsigned long long, std::pair<unsigned int, unsigned int> >::iterator it;
75  if((it = wMap.find(wordId)) != wMap.end())
76  {
77  (*it).second.second--;
78  }
79 }
80 
81 unsigned int NotStricktChain::wCount() const
82 {
83  return wMap.size();
84 }
85 #endif