-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.c
More file actions
75 lines (62 loc) · 1.71 KB
/
utils.c
File metadata and controls
75 lines (62 loc) · 1.71 KB
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdbool.h>
#include <stdint.h>
#include <math.h>
#include "hash.h"
#include "hash_f.h"
#include "utils.h"
#include "bloom.h"
#define TAILLE_MAX 256
int compter_lignes(const char *nom_fichier) {
FILE *f = fopen(nom_fichier, "r");
assert(f != NULL);
int lignes = 0;
char buffer[TAILLE_MAX];
while (fgets(buffer, sizeof(buffer), f) != NULL) {
lignes++;
}
fclose(f);
return lignes;
}
void afficher_stats_bloom(const bloom_filter *bf, int nb_mots) {
int bits_occupes = 0;
for (int i = 0; i < bf->size; i++) {
if (bf->bits[i]) bits_occupes++;
}
printf("\n--- Statistiques Bloom Filter ---\n");
printf("Taille Bloom : %d\n", bf->size);
printf("Mots insérés : %d\n", nb_mots);
}
int remplir_table_bloom(bloom_filter *bf, const char *nom_fichier) {
FILE *f = fopen(nom_fichier, "r");
assert(f != NULL);
char ligne[TAILLE_MAX];
int nb_mots = 0;
while (fgets(ligne, sizeof(ligne), f)) {
ligne[strcspn(ligne, "\n")] = '\0';
if (ligne[0] == '\0') continue;
bloom_add(bf, ligne);
nb_mots++;
}
fclose(f);
return nb_mots;
}
int calculer_intersection_bloom(const bloom_filter *bf, const char *nom_fichier2) {
FILE *f = fopen(nom_fichier2, "r");
assert(f != NULL);
char ligne[TAILLE_MAX];
int communs = 0;
while (fgets(ligne, sizeof(ligne), f)) {
ligne[strcspn(ligne, "\n")] = '\0';
if (ligne[0] == '\0') continue;
if (bloom_check((bloom_filter *)bf, ligne)) {
printf("%s\n", ligne);
communs++;
}
}
fclose(f);
return communs;
}