Glossygloss  0.2
Glossygloss is set of classes to use several data structure as Tree or hash table.
 All Classes Files Functions Variables Macros Pages
dictionnaire_hash.hpp
Go to the documentation of this file.
1 
34 #ifndef DICTIONNAIRE_HPP
35 #define DICTIONNAIRE_HPP
36 
37 
38 #include "hashtable.hpp"
39 #include <utility>
40 
41 
42 using std::pair;
43 
44 
53 bool triPair(const pair<string, int> &first, const pair<string, int> &second){
54  return first.second > second.second;
55 }
56 
57 class Dictionnaire{
58 
59  private :
62 
63  public :
64 
69 
70 
75 
81  bool contientMot(string mot){
82  return dico.contains(mot);
83  }
84 
89  void ajouterMot(string mot){
90  dico.put(mot,1);
91  }
92 
98  void associerMot(string mot){
99  dico.put(mot,dico.get(mot)+1);
100  }
101 
107  int valeurAssociee(string mot){
108  try{
109  return dico.get(mot);;
110  }catch(HashtableException e){
111  return 0;
112  }
113  }
114 
119  void plusFrequentes(pair<string,int> *frequences){
120  forward_list<pair<string, int>> pairs;
121  // on récupère les mots avec leurs fréquences
122  dico.getPairs(pairs);
123  // on tri la liste
124  pairs.sort(&triPair); // complexité : n(log(n))
125  auto it_pairs = pairs.begin();
126  int i = 0;
127  // on met les dix premières pairs dans le tableau
128  while(i<10 and pairs.end() != it_pairs){
129  frequences[i++] = *it_pairs;
130  ++it_pairs;
131  }
132  }
133 };
134 
138 template<> unsigned computehash<string>(string element){
139  // calcul de la clé de hachage en utilisant fonction fournie par API
140  std::hash<string> hashcalculator;
141  return hashcalculator(element);
142 }
143 
144 #endif // DICTIONNAIRE_HPP
void ajouterMot(string mot)
Definition: dictionnaire_hash.hpp:89
unsigned computehash< string >(string element)
Definition: dictionnaire_hash.hpp:138
void plusFrequentes(pair< string, int > *frequences)
Definition: dictionnaire_hash.hpp:119
Exception class to manage Hashtable errors.
Definition: hashtable.hpp:80
void associerMot(string mot)
Definition: dictionnaire_hash.hpp:98
Hashtable< string, int > dico
Definition: dictionnaire_hash.hpp:61
bool triPair(const pair< string, int > &first, const pair< string, int > &second)
Definition: dictionnaire_hash.hpp:53
Dictionnaire()
Definition: dictionnaire_hash.hpp:68
void put(const string &word)
Definition: treestring.hpp:338
~Dictionnaire()
Definition: dictionnaire_hash.hpp:74
bool contientMot(string mot)
Definition: dictionnaire_hash.hpp:81
TreeString dico
Definition: dictionnaire_arbre.hpp:58
int valeurAssociee(string mot)
Definition: dictionnaire_hash.hpp:107
Definition: dictionnaire_arbre.hpp:55