Amélioration de l'affichage verbeux sur +eurs fichiers
This commit is contained in:
parent
6cea8e8db5
commit
3aef7806cd
|
@ -54,14 +54,16 @@ double* _createFrequencies(const char* filepath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void compress(const char* filepath) {
|
void compress(const char* filepath) {
|
||||||
printVerbose("Calcul des fréquences d'apparition de chaque caractère\n");
|
printVerbose("Compression du fichier '%s'...\n", filepath);
|
||||||
|
printVerbose("Calcul des fréquences d'apparition des caractères.\n");
|
||||||
|
|
||||||
double* frequencies = _createFrequencies(filepath);
|
double* frequencies = _createFrequencies(filepath);
|
||||||
|
|
||||||
if (isVerbose()) {
|
if (isVerbose()) {
|
||||||
printFrequenciesTable(frequencies, NUM_CHARS);
|
printFrequenciesTable(frequencies, NUM_CHARS);
|
||||||
}
|
}
|
||||||
|
|
||||||
printVerbose("\nConstruction de l'arbre de Huffman\n");
|
printVerbose("\nConstruction de l'arbre de Huffman.\n");
|
||||||
HufTree tree = createTree(frequencies);
|
HufTree tree = createTree(frequencies);
|
||||||
|
|
||||||
free(frequencies);
|
free(frequencies);
|
||||||
|
@ -71,7 +73,7 @@ void compress(const char* filepath) {
|
||||||
printTree(tree);
|
printTree(tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
printVerbose("\nÉtiquetage des feuilles de l'arbre\n");
|
printVerbose("\nÉtiquetage des feuilles de l'arbre.\n");
|
||||||
char** labels = createTreeLabels(tree);
|
char** labels = createTreeLabels(tree);
|
||||||
|
|
||||||
freeTree(tree);
|
freeTree(tree);
|
||||||
|
@ -81,4 +83,5 @@ void compress(const char* filepath) {
|
||||||
}
|
}
|
||||||
|
|
||||||
freeTreeLabels(labels);
|
freeTreeLabels(labels);
|
||||||
|
labels = NULL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -74,44 +74,44 @@ int _maxDepth(HufVertex vert) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void printFrequenciesTable(double* table, size_t size) {
|
void printFrequenciesTable(double* table, size_t size) {
|
||||||
printf("╭─┬───┬─────────╮\n");
|
printf("┌─┬────┬─────────┐\n");
|
||||||
printf("│C│num│fréquence│\n");
|
printf("│C│code│fréquence│\n");
|
||||||
printf("├─┼───┼─────────┤\n");
|
printf("├─┼────┼─────────┤\n");
|
||||||
|
|
||||||
double sum = 0;
|
double sum = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
if (table[i] != 0) {
|
if (table[i] != 0) {
|
||||||
printf("│%c│%3d│%9lf│\n", _safeChar(i), (int) i, table[i]);
|
printf("│%c│%4d│%9.4lf│\n", _safeChar(i), (int) i, table[i]);
|
||||||
sum += table[i];
|
sum += table[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("├─┴───┼─────────┤\n");
|
printf("├─┴────┼─────────┤\n");
|
||||||
printf("│Total│%9lf│\n", sum);
|
printf("│ Total│%9.4lf│\n", sum);
|
||||||
printf("╰─────┴─────────╯\n");
|
printf("└──────┴─────────┘\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void printLabelsTable(char** table, size_t size) {
|
void printLabelsTable(char** table, size_t size) {
|
||||||
printf("╭─┬───┬────────────────╮\n");
|
printf("┌─┬────┬────────────────┐\n");
|
||||||
printf("│C│num│ étiquette│\n");
|
printf("│C│code│ étiquette│\n");
|
||||||
printf("├─┼───┼────────────────┤\n");
|
printf("├─┼────┼────────────────┤\n");
|
||||||
|
|
||||||
double total_length = 0;
|
double total_length = 0;
|
||||||
size_t label_count = 0;
|
size_t label_count = 0;
|
||||||
|
|
||||||
for (size_t i = 0; i < size; i++) {
|
for (size_t i = 0; i < size; i++) {
|
||||||
if (table[i] != 0) {
|
if (table[i] != 0) {
|
||||||
printf("│%c│%3d│%16s│\n", _safeChar(i), (int) i, table[i]);
|
printf("│%c│%4d│%16s│\n", _safeChar(i), (int) i, table[i]);
|
||||||
|
|
||||||
total_length += strlen(table[i]);
|
total_length += strlen(table[i]);
|
||||||
label_count++;
|
label_count++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("├─┴───┴────┬───────────┤\n");
|
printf("├─┴────┴───┬────────────┤\n");
|
||||||
printf("│Long. moy.│%11lf│\n", total_length / label_count);
|
printf("│Long. moy.│%12.4lf│\n", total_length / label_count);
|
||||||
printf("╰──────────┴───────────╯\n");
|
printf("└──────────┴────────────┘\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
char _safeChar(char input) {
|
char _safeChar(char input) {
|
||||||
|
|
|
@ -81,5 +81,10 @@ int main(int argc, char** argv) {
|
||||||
while (*filepath != NULL) {
|
while (*filepath != NULL) {
|
||||||
compress(*filepath);
|
compress(*filepath);
|
||||||
filepath++;
|
filepath++;
|
||||||
|
|
||||||
|
// Ligne de séparation entre les différents fichier
|
||||||
|
if (*filepath != NULL) {
|
||||||
|
printVerbose("\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue