Il te manque le mot clé 'struct' :
Code:typedef struct tableauDynamique_struct tableHachage_struct[TAILLEHASH];
Version imprimable
Il te manque le mot clé 'struct' :
Code:typedef struct tableauDynamique_struct tableHachage_struct[TAILLEHASH];
Merci Pouet :)
mais aprement ya une autre qui cloche là :roll:
|erreur: expected identifier or ‘(’ before ‘[’ token|Code:typedef struct tableHachage_struct[TAILLEHASH];
erreur: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘*’ token|Code:tableHachage_struct * CreerSimpleTableHachage()
merci
La première partie, je crois que le typedef est en trop.
La deuxième erreur, le struct est manquant.
Les erreurs que l'on vient de voir, indiquent que le compileur ne reconnait pas ce qu'il y avant l'endroit indiqué par l'erreur. Soit il ne reconnait pas le type comme tel.
Code:
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 #define DECLARE_REALLOC(name, type) \ int realloc_ ## name (type **ppMem, size_t nNew); #define IMPLEMENT_REALLOC(name, type) \ int realloc_ ## name (type **ppMem, size_t nNew)\ {\ int ret = -1;\ type * pNew = realloc(*ppMem, nNew * sizeof(**ppMem));\ if(pNew != NULL || nNew==0)\ {\ *ppMem = pNew;\ ret = 0;\ }\ return ret;\ } IMPLEMENT_REALLOC(struct, struct BiSequence) struct BiSequence { MotCompact *seq; MotCompact *MotGauche; MotCompact *MotDroit; }; struct TableauDynamique_struct { struct BiSequence *tab; size_t taille; size_t capacite; }; //constructeur pour TableauDynamique_struct void TableauDynamique_struct_ctor(struct TableauDynamique_struct *pThis) { pThis->tab = NULL; pThis->taille = 0; pThis->capacite = 0; } //destructeur void TableauDynamique_struct_dtor(struct TableauDynamique_struct *pThis) { free(pThis->tab); pThis->tab = NULL; pThis->taille = 0; pThis->capacite = 0; } int TableauDynamique_struct_ajouter(struct TableauDynamique_struct *pThis, struct BiSequence const* pcNouveau) { assert(pThis->taille <= pThis->capacite); /* Agrandir le tableau si besoin est. */ if(pThis->taille == pThis->capacite) { size_t nouvelleCapacite = (pThis->capacite < 4 ? 4 : (size_t)(pThis->capacite*1.5)); if(realloc_struct(&pThis->tab, nouvelleCapacite) >= 0) { pThis->capacite = nouvelleCapacite; } else return -1; } pThis->tab[pThis->taille++] = *pcNouveau; }
Bizarre. pour moi, ça devrait compiler... Sauf que tu devrais définir la structure BiSequence avant d'appeler la macro IMPLEMENT_REALLOC.
Ceci compile sans problème chez moi, du moment que le type MotCompact est déclaré.Code:
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 #define DECLARE_REALLOC(name, type) \ int realloc_ ## name (type **ppMem, size_t nNew); #define IMPLEMENT_REALLOC(name, type) \ int realloc_ ## name (type **ppMem, size_t nNew)\ {\ int ret = -1;\ type * pNew = realloc(*ppMem, nNew * sizeof(**ppMem));\ if(pNew != NULL || nNew==0)\ {\ *ppMem = pNew;\ ret = 0;\ }\ return ret;\ } struct BiSequence { MotCompact *seq; MotCompact *MotGauche; MotCompact *MotDroit; }; IMPLEMENT_REALLOC(struct, struct BiSequence) struct TableauDynamique_struct { struct BiSequence *tab; size_t taille; size_t capacite; }; /*constructeur pour TableauDynamique_struct*/ void TableauDynamique_struct_ctor(struct TableauDynamique_struct *pThis) { pThis->tab = NULL; pThis->taille = 0; pThis->capacite = 0; } /*destructeur*/ void TableauDynamique_struct_dtor(struct TableauDynamique_struct *pThis) { free(pThis->tab); pThis->tab = NULL; pThis->taille = 0; pThis->capacite = 0; } int TableauDynamique_struct_ajouter(struct TableauDynamique_struct *pThis, struct BiSequence const* pcNouveau) { assert(pThis->taille <= pThis->capacite); /* Agrandir le tableau si besoin est. */ if(pThis->taille == pThis->capacite) { size_t nouvelleCapacite = (pThis->capacite < 4 ? 4 : (size_t)(pThis->capacite*1.5)); if(realloc_struct(&pThis->tab, nouvelleCapacite) >= 0) { pThis->capacite = nouvelleCapacite; } else return -1; } pThis->tab[pThis->taille++] = *pcNouveau; return 0; }
Bonsoir,
J'ai une erreur dans ma fonction CreerSimpleTableHachage():
erreur: ‘TableHachage_BiSequence’ undeclared (first use in this function)|
à ce niveau :
Franchement je vois pas pourquoi il recoannait pas cette variable :roll:Code:TableHachage_BiSequence * THash = AllocExit( sizeof * THash);
Une idée svp?
merci
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 struct TableHachage_BiSequence { struct TableauDynamique_BiSequence seaux[TAILLEHASH]; }; struct TableHachage_BiSequence * CreerSimpleTableHachage() { TableHachage_BiSequence * THash = AllocExit( sizeof * THash); size_t i; for(i=0;i<TAILLEHASH; i++) { TableauDynamique_BiSequence_ctor(&THash[i]); } return THash; }
Il manque simplement le mot clé struct.
Je vais expliquer ( essayer de le faire ) en détail.
Lorsque l'on définit une structure, si l'on veut utiliser celle ci, il faut dire au compilateur que c'est une structure. Donc on utilise le mot clé 'structé' pour indiquer au compilateur que l'on fait référence à un type qui est une structure.
Maintenant, il existe une méthode pour ne pas avoir à toujours taper 'struct'.
Pour ce faire il faut définir la structure comme suit:
Pourquoi ?Code:
1
2
3
4
5
6 typedef struct MyStruct { int x; int y; }MyStruct;
Simplement car le typedef va faire un alias sur la struct Mystruct, qui sera appelé Mystruct.
Du coup pour le compilateur, à chaque fois que l'on ecrit MyStruct, pour lui se sera comme 'struct MyStruct'.
Bonjour, donc là me reste la fonction le remplissage de la table de hachage à partir du fichier binaire et donc on a besoin à une fonction de ce genre :
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 /*---------------------------------------------------------------------------- Fonction de chargement.*/ static int LireTableFichBinaire1fr(size_t verifTaille, struct char_fbtAllocator *pAllocCaracs, struct int_fbtAllocator *pAllocLignes, MotCompact *pMots, size_t *piMot, size_t nbMots) { int retour = -1; char nomFich[FILENAME_MAX]; FILE *pfIn; if(snprintf(nomFich, ARRAYSIZE(nomFich), "table1MotFR.bin") >= ARRAYSIZE(nomFich)) { errno = E2BIG; return -1; } pfIn = fopen(nomFich, LECTURE_SEQUENTIELLE_BINAIRE); if(pfIn != NULL) { retour = LireTableFichierOuvert(pfIn, verifTaille, pAllocCaracs, pAllocLignes, pMots, piMot, nbMots); fclose(pfIn); } return retour; }
Normalement, tu as toujours une fonction pour lire le fichier binaire et en faire un tableau de structures MotCompact.
Tu peux créer et remplir la table de hachage à partir dudit tableau, après la lecture...
Bonjour Médinoc, tu vas bien? ;)
c'est a dire je rempli la table de hachage apres avoir creer et rempli les tableau MotCompact ??
donc Là au lieu de mettre la fonction CalculerRegles, je mets une fonction qui remplit la table de hachage c'est ca?Code:
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 void remplirTableauFichier () { struct char_fbtAllocator *pAllocCaracs2=NULL, *pAllocCaracs4=NULL; struct int_fbtAllocator *pAllocLignes2=NULL, *pAllocLignes4=NULL; size_t *pTailles2=NULL,*pTailles4=NULL, nbMots2=0,nbMots4=0; size_t nbCaracs2=0, nbCaracs4=0; unsigned int nbLignes2=0,nbLignes4=0; if(CompterToutesTablesFichBinaire2fr(&pTailles2, &nbCaracs2, &nbLignes2)<0) goto LNettoyage; if(CompterToutesTablesFichBinaire2en(&pTailles4, &nbCaracs4, &nbLignes4)<0) goto LNettoyage; nbMots2 = SommeTailles2fr(pTailles2); nbMots4 = SommeTailles2en(pTailles4); pAllocCaracs2 = char_CreateFbtAllocator(nbCaracs2); pAllocCaracs4= char_CreateFbtAllocator(nbCaracs4); if(pAllocCaracs2==NULL|| pAllocCaracs4==NULL) goto LNettoyage; pAllocLignes2 = int_CreateFbtAllocator(nbLignes2); pAllocLignes4 = int_CreateFbtAllocator(nbLignes4); if( pAllocLignes2==NULL|| pAllocLignes4==NULL) goto LNettoyage; MotCompact * pMots2fr = LireToutesTablesFichBinaire2fr(pTailles2, pAllocCaracs2, pAllocLignes2); MotCompact * pMots2en = LireToutesTablesFichBinaire2en(pTailles4, pAllocCaracs4, pAllocLignes4); if(pMots2fr==NULL|| pMots2en==NULL) { DetruireTableauMotsCompacts(pMots2fr), pMots2fr=NULL; DetruireTableauMotsCompacts(pMots2en), pMots2en=NULL; goto LNettoyage; } // calculerlesRegles1( pMots2fr,pMots1en,nbMots2,nbMots3); DetruireTableauMotsCompacts(pMots2fr), pMots2fr=NULL; DetruireTableauMotsCompacts(pMots2en), pMots2en=NULL; //retour = EXIT_SUCCESS; LNettoyage: free(pTailles2), pTailles2=NULL; free(pTailles4), pTailles4=NULL; }
Merci
Ce que je te conseille, c'est de mettre ça carrément dans une autre fonction, appelée après la lecture.
Et renomme ta fonction RemplirTableauFichier en TraiterFichiersBinaires(), vu que c'est ce qu'elle fait.
Donc le main va contenir :
- fonction de lecture du fichier binaire
-fonction de création et remplissage des tableau MotCompact
-fonction pour creer et remplir la table de hachage
c'est bien ca?
MerciCode:
1
2
3
4
5
6
7
8
9
10 //Remplissage void RemplirTableHachage(MotCompact const pcMots1[], struct TableHachage_BiSequence * THash,int nbmot1) { size_t iMot1; //parcourir le tableau MotCompact for(iMot1=0 ; iMot1<nbmot1 ; iMot1++) { TableHachage_BiSequence_ajouter(THash, pcMots1+iMot1); } }
Voilà le code actuel :
des critiques svp sachant qu'il compile bien :)Code:
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
39
40
41
42
43
44
45
46
47
48 void remplirTableauFichier () { struct TableHachage_BiSequence* TH; struct char_fbtAllocator *pAllocCaracs2=NULL, *pAllocCaracs4=NULL; struct int_fbtAllocator *pAllocLignes2=NULL, *pAllocLignes4=NULL; size_t *pTailles2=NULL,*pTailles4=NULL, nbMots2=0,nbMots4=0; size_t nbCaracs2=0, nbCaracs4=0; unsigned int nbLignes2=0,nbLignes4=0; if(CompterToutesTablesFichBinaire2fr(&pTailles2, &nbCaracs2, &nbLignes2)<0) goto LNettoyage; if(CompterToutesTablesFichBinaire2en(&pTailles4, &nbCaracs4, &nbLignes4)<0) goto LNettoyage; nbMots2 = SommeTailles2fr(pTailles2); nbMots4 = SommeTailles2en(pTailles4); pAllocCaracs2 = char_CreateFbtAllocator(nbCaracs2); pAllocCaracs4= char_CreateFbtAllocator(nbCaracs4); if(pAllocCaracs2==NULL|| pAllocCaracs4==NULL) goto LNettoyage; pAllocLignes2 = int_CreateFbtAllocator(nbLignes2); pAllocLignes4 = int_CreateFbtAllocator(nbLignes4); if( pAllocLignes2==NULL|| pAllocLignes4==NULL) goto LNettoyage; MotCompact * pMots2fr = LireToutesTablesFichBinaire2fr(pTailles2, pAllocCaracs2, pAllocLignes2); MotCompact * pMots2en = LireToutesTablesFichBinaire2en(pTailles4, pAllocCaracs4, pAllocLignes4); if(pMots2fr==NULL|| pMots2en==NULL) { DetruireTableauMotsCompacts(pMots2fr), pMots2fr=NULL; DetruireTableauMotsCompacts(pMots2en), pMots2en=NULL; goto LNettoyage; } TH=CreerSimpleTableHachage(); RemplirTableHachage(pMots2fr, TH,nbMots2); // calculerlesRegles1( pMots2fr,pMots1en,nbMots2,nbMots3); DetruireTableauMotsCompacts(pMots2fr), pMots2fr=NULL; DetruireTableauMotsCompacts(pMots2en), pMots2en=NULL; //retour = EXIT_SUCCESS; LNettoyage: free(pTailles2), pTailles2=NULL; free(pTailles4), pTailles4=NULL; } int main(int argc, char *argv[]) { remplirTableauFichier(); return 0; }
Bonsoir à tous, j'ai des souci avec ma fonction de comparaison :aie: :
il m'affiche :erreur: expected expression before ‘struct’| ici :Code:
1
2
3
4
5
6
7 int cmpTableauDynamique_struct(const void* t1, const void* t2) { // On compare les deux éléments struct BiSequence ds1 = struct(BiSequence*)t1; struct BiSequence ds2 = struct(BiSequence*)t2; return strcmp (ds1->seq, ds2->seq); }
et|erreur: invalid type argument of ‘->’ (have ‘struct BiSequence’)| au niveau du returnCode:
1
2 struct BiSequence ds1 = struct(BiSequence*)t1; struct BiSequence ds2 = struct(BiSequence*)t2;
des idée svp?Code:
1
2
3
4
5
6
7
8 void TrieTable( struct TableHachage_BiSequence * THash,size_t nbmot1) { size_t i; for(i=0;i<nbmot1;i++) { qsort ( TableauDynamique_BiSequence->tab , struct TableauDynamique_BiSequence->taille , sizeof(BiSequence), cmpTableauDynamique_struct ); } }
merci
Tes mots 'struct' sont mal placés.
De plus pour utiliser l'opérateur -> il faut que ta structure soit en fait un pointeur de structure sinon il faut utiliser le point.
Code:
1
2
3
4
5
6
7 int cmpTableauDynamique_struct(const void* t1, const void* t2) { // On compare les deux éléments struct BiSequence *ds1 = (struct BiSequence*) t1; struct BiSequence *ds2 = (struct BiSequence*) t2; return strcmp (ds1->seq, ds2->seq); }
Merci Pouet :)
mais là le compilateur m'inque que l'initialisation est invalide:?Code:
1
2 struct BiSequence ds1 = (struct BiSequence*)t1; struct BiSequence ds2 = (struct BiSequence*)t2;
et là :passing argument 1 of ‘strlen’ from incompatible pointer type|Code:return strcmp (ds1.seq, ds2.seq);
Merci beaucoup
Si tu regardes bien dans le code que je t'ai donné j'ai mis des étoiles sur les ds1 et ds2 ;)
Donc tu ne mets pas de point mais bien les -> ;)Code:
1
2 struct BiSequence *ds1 struct BiSequence *ds2
voilà c'est bon,enfin je pense..:roll:
Code:
1
2
3
4
5
6
7 int cmpTableauDynamique_struct(const void* t1, const void* t2) { // On compare les deux éléments struct BiSequence *ds1 = (struct BiSequence*)t1; struct BiSequence *ds2 = (struct BiSequence*)t2; return strcmp (GetMotCompact(ds1->seq), GetMotCompact(ds2->seq)); }
Code:
1
2
3
4
5
6
7
8 void TrieTable( struct TableHachage_BiSequence * THash,size_t nbmot1,struct TableauDynamique_BiSequence *TabDyn , struct BiSequence *bs) { size_t i; for (i=0;i<nbmot1;i++) { qsort ( TabDyn->tab , TabDyn->taille , sizeof(bs), cmpTableauDynamique_struct ); } }
Bonsoir à tous, voilà les avancement dans le code.
Je pense là me reste que la phase de calcul des regles
merci
Code:
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278 int main(int argc, char *argv[]) { TraiterFichBinaire(); return 0; } void TraiterFichBinaire () { struct TableHachage_BiSequence* TH_FR; struct TableHachage_BiSequence* TH_EN; // Ces variables sont pour les sequences struct char_fbtAllocator *pAllocCaracsFR_seq=NULL, *pAllocCaracsEN_seq=NULL; struct int_fbtAllocator *pAllocLignesFR_seq=NULL, *pAllocLignesEN_seq=NULL; size_t *pTaillesTableFR_seq=NULL,*pTaillesTableEN_seq=NULL; size_t nbCaracsFR_seq=0, nbCaracsEN_seq=0, nbSeqFR=0,nbSeqEN=0; unsigned int nbLignesFR_seq=0,nbLignesEN_seq=0; MotCompact * pSeqFR = NULL; MotCompact * pSeqEN = NULL; // Ces variables sont pour les mots (gauches et droits) struct char_fbtAllocator *pAllocCaracsFR_mots=NULL, *pAllocCaracsEN_mots=NULL; struct int_fbtAllocator *pAllocLignesFR_mots=NULL, *pAllocLignesEN_mots=NULL; size_t *pTaillesTableFR_mots=NULL,*pTaillesTableEN_mots=NULL; size_t nbCaracsFR_mots=0, nbCaracsEN_mots=0, nbMotsFR=0,nbMotsEN=0; unsigned int nbLignesFR_mots=0,nbLignesEN_mots=0; MotCompact * pMotsFR = NULL; MotCompact * pMotsEN = NULL; // Chargement des sequences (FR et EN) { if (CompterToutesTablesFichBinaire2fr(&pTaillesTableFR_seq, &nbCaracsFR_seq, &nbLignesFR_seq)<0) { goto LNettoyage; } if (CompterToutesTablesFichBinaire2en(&pTaillesTableEN_seq, &nbCaracsEN_seq, &nbLignesEN_seq)<0) { goto LNettoyage; } nbSeqFR = SommeTailles(pTaillesTableFR_seq); nbSeqEN = SommeTailles(pTaillesTableEN_seq); pAllocCaracsFR_seq = char_CreateFbtAllocator(nbCaracsFR_seq); pAllocCaracsEN_seq= char_CreateFbtAllocator(nbCaracsEN_seq); if (pAllocCaracsFR_seq==NULL || pAllocCaracsEN_seq==NULL) { goto LNettoyage; } pAllocLignesFR_seq = int_CreateFbtAllocator(nbLignesFR_seq); pAllocLignesEN_seq = int_CreateFbtAllocator(nbLignesEN_seq); if ( pAllocLignesFR_seq==NULL|| pAllocLignesEN_seq==NULL) { goto LNettoyage; } pSeqFR = LireToutesTablesFichBinaire2fr(pTaillesTableFR_seq, pAllocCaracsFR_seq, pAllocLignesFR_seq); pSeqEN = LireToutesTablesFichBinaire2en(pTaillesTableEN_seq, pAllocCaracsEN_seq, pAllocLignesEN_seq); if (pSeqFR==NULL|| pSeqEN==NULL) { DetruireTableauMotsCompacts(pSeqFR), pSeqFR=NULL; DetruireTableauMotsCompacts(pSeqEN), pSeqEN=NULL; goto LNettoyage; } } // Chargement des mots (gauches et droites) (FR et EN) { if (CompterToutesTablesFichBinaire1fr(&pTaillesTableFR_mots, &nbCaracsFR_mots, &nbLignesFR_mots)<0) { goto LNettoyage; } if (CompterToutesTablesFichBinaire1en(&pTaillesTableEN_mots, &nbCaracsEN_mots, &nbLignesEN_mots)<0) { goto LNettoyage; } nbMotsFR = SommeTailles(pTaillesTableFR_mots); nbMotsEN = SommeTailles(pTaillesTableEN_mots); pAllocCaracsFR_mots = char_CreateFbtAllocator(nbCaracsFR_mots); pAllocCaracsEN_mots = char_CreateFbtAllocator(nbCaracsEN_mots); if (pAllocCaracsFR_mots == NULL || pAllocCaracsEN_mots == NULL) { goto LNettoyage; } pAllocLignesFR_mots = int_CreateFbtAllocator(nbLignesFR_mots); pAllocLignesEN_mots = int_CreateFbtAllocator(nbLignesEN_mots); if ( pAllocLignesFR_mots == NULL || pAllocLignesEN_mots == NULL) { goto LNettoyage; } pMotsFR = LireToutesTablesFichBinaire1fr(pTaillesTableFR_mots, pAllocCaracsFR_mots, pAllocLignesFR_mots); pMotsEN = LireToutesTablesFichBinaire1en(pTaillesTableEN_mots, pAllocCaracsEN_mots, pAllocLignesEN_mots); if (pMotsFR==NULL|| pMotsEN==NULL) { DetruireTableauMotsCompacts(pMotsFR), pMotsFR=NULL; DetruireTableauMotsCompacts(pMotsEN), pMotsEN=NULL; goto LNettoyage; } } TH_FR=CreerSimpleTableHachage(); TH_EN=CreerSimpleTableHachage(); RemplirTableHachageSeq(pSeqFR, TH_FR,nbSeqFR); RemplirTableHachageMots(pMotsFR, TH_FR,nbMotsFR); RemplirTableHachageSeq(pSeqEN, TH_EN,nbSeqEN); RemplirTableHachageMots(pMotsEN, TH_EN,nbMotsEN); // calculerlesRegles1( pSeqFR,pMots1en,nbSeqFR,nbMots3); DetruireTableauMotsCompacts(pSeqFR), pSeqFR=NULL; DetruireTableauMotsCompacts(pSeqEN), pSeqEN=NULL; DetruireTableauMotsCompacts(pMotsFR), pMotsFR=NULL; DetruireTableauMotsCompacts(pMotsEN), pMotsEN=NULL; //retour = EXIT_SUCCESS; LNettoyage: free(pTaillesTableFR_seq), pTaillesTableFR_seq=NULL; free(pTaillesTableEN_seq), pTaillesTableEN_seq=NULL; free(pTaillesTableFR_mots), pTaillesTableFR_mots=NULL; free(pTaillesTableEN_mots), pTaillesTableEN_mots=NULL; } struct TableHachage_BiSequence { struct TableauDynamique_BiSequence seaux[TAILLEHASH]; }; struct TableHachage_BiSequence * CreerSimpleTableHachage() { struct TableHachage_BiSequence * THash = AllocExit( sizeof * THash); size_t i; for (i=0;i<TAILLEHASH; i++) { TableauDynamique_BiSequence_ctor(&(THash->seaux[i])); } return THash; } /* Hache une chaîne de caractères. */ unsigned int hash_chaine(const char * chn) { unsigned int val = 0; for (; *chn != '\0'; ++chn) { val = *chn + 31 * val; } return val % TAILLEHASH; } int TableHachage_BiSequence_ajouter_seq(struct TableHachage_BiSequence *pThis, const MotCompact* pNouvelSeq) { struct BiSequence bs = { NULL, NULL, NULL }; unsigned int cle = hash_chaine(GetMotCompact(pNouvelSeq)); bs.seq = pNouvelSeq; return TableauDynamique_BiSequence_ajouter(&(pThis->seaux[cle]), &bs); } int TableHachage_BiSequence_ajouter_mots(struct TableHachage_BiSequence *pThis, const MotCompact* pNouveauMotG, const MotCompact* pNouveauMotD) { const char* motG = GetMotCompact(pNouveauMotG); const char* motD = GetMotCompact(pNouveauMotD); char* seqSim = NULL; size_t nbLettersEnsemble = strlen(motG) + strlen(motD) + 2; // + 2 car il nous faut un espace et un '\0' unsigned int cle = 0; seqSim = malloc(nbLettersEnsemble * sizeof(char)); if ( seqSim == NULL ) { printf("Problème allocation mémoire dans TableHachage_BiSequence_ajouter_mots\n"); return -1; } // Reconstruction de la séquence à partir de deux mots strcat(seqSim, motG); strcat(seqSim, " "); strcat(seqSim, motD); cle = hash_chaine(seqSim); // Grace à la clé nous avons la BiSequence correspondante, donc nous remplissons la structure avec les mots // Comme nous avons une tablea de hachage qui contient des tableaux dynamique, le premier élément n'est peut être pas le bon // Nous parcourons le tableau pour savoir { size_t i = 0; int flag = 0; for ( i = 0 ; i < pThis->seaux[cle].taille ; i++ ) { // C'est la bonne sequence if ( strcmp(GetMotCompact(pThis->seaux[cle].tab[i].seq), seqSim) == 0 ) { pThis->seaux[cle].tab[i].MotGauche = pNouveauMotG; pThis->seaux[cle].tab[i].MotDroit = pNouveauMotD; // Fin de boucle i = pThis->seaux[cle].taille; flag = 1; } } if ( flag == 0 ) printf("La sequence n'a pas ete trouve\n"); } free (seqSim); return 0; } // Remplissage avec les séquences. Il faut que cette fonction soit appelé avant celle pour les mots void RemplirTableHachageSeq(MotCompact const pcSeq1[], struct TableHachage_BiSequence * THash,size_t nbSeq) { size_t iSeq; //parcourir le tableau MotCompact for (iSeq=0 ; iSeq < nbSeq ; iSeq++) { TableHachage_BiSequence_ajouter_seq(THash, pcSeq1+iSeq); } } // Remplissage avec les mots. Il faut que cette fonction soit appelé après celle pour les séquences void RemplirTableHachageMots(MotCompact const pcMots[], struct TableHachage_BiSequence * THash,size_t nbMot) { size_t iMot; size_t jMot; // parcourir le tableau MotCompact pour faire toute les association possible // Parcours quadratique for (iMot=0 ; iMot < nbMot ; iMot++) { for ( jMot = iMot + 1 ; jMot < nbMot ; jMot++ ) { TableHachage_BiSequence_ajouter_mots(THash, pcMots+iMot, pcMots+jMot); } } } int cmpTableauDynamique_struct(const void* t1, const void* t2) { // On compare les deux éléments struct BiSequence *ds1 = (struct BiSequence*)t1; struct BiSequence *ds2 = (struct BiSequence*)t2; return strcmp (GetMotCompact(ds1->seq), GetMotCompact(ds2->seq)); } void TrieTable( struct TableHachage_BiSequence * TH) { size_t i; for (i=0;i<TAILLEHASH;i++) { qsort ( TH->seaux[i].tab, TH->seaux[i].taille, sizeof(struct BiSequence), cmpTableauDynamique_struct); } }