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(
|
2016-10-12 10:57:57 +00:00
|
|
|
"[%8p] Sommet %c (%4f) : parent %8p, enfants %8p %8p\n",
|
2016-10-12 10:28:38 +00:00
|
|
|
(void*) vertex, vertex->value, vertex->frequency,
|
2016-10-12 10:57:57 +00:00
|
|
|
(void*) vertex->parent, (void*) vertex->child_l,
|
|
|
|
(void*) vertex->child_r
|
2016-10-12 10:28:38 +00:00
|
|
|
);
|
|
|
|
}
|
2016-10-06 16:43:57 +00:00
|
|
|
|
2016-10-12 10:57:57 +00:00
|
|
|
printf("\n\n--- 3 : ATTRIBUTION DES CODES ---\n\n");
|
|
|
|
|
2016-10-06 16:43:57 +00:00
|
|
|
return 0;
|
|
|
|
}
|