2016-10-06 16:43:57 +00:00
|
|
|
#include "../include/huf.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int main(int argc, const char** argv) {
|
|
|
|
if (argc != 2) {
|
2016-10-12 10:28:38 +00:00
|
|
|
fprintf(stderr, "Usage : compress <fichier>\n");
|
|
|
|
fprintf(stderr, "Paramètre fichier manquant.\n");
|
2016-10-06 16:43:57 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
double* frequencies = computeFrequencies(argv[1]);
|
|
|
|
double sum = 0;
|
|
|
|
|
2016-10-12 10:28:38 +00:00
|
|
|
printf("--- 1 : CALCUL DES FRÉQUENCES ---\n\n");
|
|
|
|
|
2016-10-06 16:43:57 +00:00
|
|
|
for (int i = 0; i < 256; i++) {
|
|
|
|
if (frequencies[i] != 0) {
|
|
|
|
sum += frequencies[i];
|
2016-10-12 10:28:38 +00:00
|
|
|
printf("%1c (%3d) : %4f\n", i, i, frequencies[i]);
|
2016-10-06 16:43:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-12 10:28:38 +00:00
|
|
|
printf("Total : %f\n\n", sum);
|
|
|
|
printf("--- 2 : CONSTRUCTION DE L'ARBRE ---\n\n");
|
|
|
|
|
|
|
|
Tree tree = buildTree(frequencies);
|
|
|
|
printf("Arbre à %zu sommets\n\n", tree.size);
|
|
|
|
|
|
|
|
for (int i = 0; i < tree.size; i++) {
|
|
|
|
Vertex* vertex = &tree.vertices[i];
|
|
|
|
|
|
|
|
printf(
|
|
|
|
"[%p] Sommet %c (%4f, %s) : parent %p\n",
|
|
|
|
(void*) vertex, vertex->value, vertex->frequency,
|
|
|
|
vertex->is_virtual ? "est virtuel" : "non virtuel",
|
|
|
|
(void*) vertex->parent
|
|
|
|
);
|
|
|
|
}
|
2016-10-06 16:43:57 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|