From 9457ec36720fe67043aad6f5c70f99e153ceaa27 Mon Sep 17 00:00:00 2001 From: PlexSheep Date: Sun, 27 Nov 2022 02:28:49 +0100 Subject: [PATCH] huffman set frequency Priorities --- huffman/huffman.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/huffman/huffman.c b/huffman/huffman.c index ee3bc2a..5d5b911 100644 --- a/huffman/huffman.c +++ b/huffman/huffman.c @@ -256,16 +256,22 @@ int main(int argc, char *argv[]) { } } if(debug){ // print refs in debug - printf("sorted reference values:\n"); - for (int i = 0; i < 256 - 1; i++){ - if(i%4==0) - printf("\n"); - printf("ref: %d \tfreq: %0.02f\t", refs[i], nodes[refs[i]].frequencyRaw); - // FIXME doesnt work for all zeros? + printf("sorted reference values:\n"); + for (int i = 0; i < 256 - 1; i++){ + if(i%4==0) + printf("\n"); + printf("ref: %d \tfreq: %0.02f\t", refs[i], nodes[refs[i]].frequencyRaw); + // FIXME doesnt work for all zeros? + } + printf("\n"); } - printf("\n"); + for (int i = 0; i < 256 - 1; i++){ // set frequencyPriorities from sorted refs + // FIXME nodes with the exact same frequency should have the same priority. + // frequenciesPrority: lower is more frequent. + nodes[refs[i]].frequencyPriority = i; } - free(refs); + // TODO rename refs array and keep until actually no longer needed. + //free(refs); // TODO build tree using Heaps // TODO write Tree and compression to file