+SHUFFNODE *shuff_buildlist(t_freq *freqtable, int *nonzerofreqs)
+{
+ int i,j = 0,nonzero = 0;
+ SHUFFNODE *inputlist;
+
+ /* Calculo cuantas frequencias > 0 hay y creo la tabla */
+ for (i = 0; i < 256; ++i) if (freqtable[i] > 0) nonzero++;
+ inputlist = (SHUFFNODE*)malloc(sizeof(SHUFFNODE)*nonzero);
+
+ /* Cargo la inputlist del huffman solo con freqs > 0 */
+ for (i = 0; i < 256; ++i)
+ if (freqtable[i] > 0) {
+ inputlist[j].symbol = i;
+ inputlist[j].freq = freqtable[i];
+ inputlist[j].lchild = NULL;
+ inputlist[j].rchild = NULL;
+ j++;
+ }
+
+ *nonzerofreqs = nonzero;
+ return inputlist;
+}
+
+SHUFFNODE *shuff_buildtree(SHUFFNODE *list, int listcount)
+{
+ SHUFFNODE *lastsymbol = list+(listcount-1);
+ SHUFFNODE *node1,*node2;
+
+ while (lastsymbol > list) {
+ /* Ordeno la lista por frecuencia descendente */
+ qsort(list,listcount,sizeof(SHUFFNODE),shuff_compnode);
+ /* Tomo los ultimos dos elementos, generando dos nodos del arbol */
+ node1 = (SHUFFNODE*)malloc(sizeof(SHUFFNODE));
+ node2 = (SHUFFNODE*)malloc(sizeof(SHUFFNODE));
+ shuff_cpynode(node1,lastsymbol-1);
+ shuff_cpynode(node2,lastsymbol);
+ lastsymbol -= 1;
+ /* Nodo ficticio con la suma de las probs y los ptros a childs */
+ lastsymbol->symbol = 256;
+ lastsymbol->freq = node1->freq + node2->freq;
+ lastsymbol->lchild = node1;
+ lastsymbol->rchild = node2;
+ --listcount;
+ }
+
+ /* Devuelvo el puntero a la raiz del arbol de huffman */
+ return lastsymbol;
+}
+
+void shuff_printcodes(SHUFFCODE *codetable,t_freq *freqtable)