]> wimlib.net Git - wimlib/blobdiff - src/compress.c
add_image.c: Add debugging statements for branch attachment
[wimlib] / src / compress.c
index 34e63997956c5a7bab91b600b06d140449a0772e..cc3c5ca5172d9374136df169a5e14548f6a4e0a1 100644 (file)
@@ -5,7 +5,7 @@
  */
 
 /*
- * Copyright (C) 2012 Eric Biggers
+ * Copyright (C) 2012, 2013 Eric Biggers
  *
  * This file is part of wimlib, a library for working with WIM files.
  *
@@ -168,7 +168,8 @@ static void huffman_tree_compute_path_lengths(HuffmanNode *node, u16 cur_len)
        }
 }
 
-/* Creates a canonical Huffman code from an array of symbol frequencies.
+/* make_canonical_huffman_code: - Creates a canonical Huffman code from an array
+ *                               of symbol frequencies.
  *
  * The algorithm used is similar to the well-known algorithm that builds a
  * Huffman tree using a minheap.  In that algorithm, the leaf nodes are
@@ -224,7 +225,7 @@ static void huffman_tree_compute_path_lengths(HuffmanNode *node, u16 cur_len)
  *                     for symbol i.
  */
 void make_canonical_huffman_code(unsigned num_syms, unsigned max_codeword_len,
-                                const u32 freq_tab[], u8 lens[],
+                                const freq_t freq_tab[], u8 lens[],
                                 u16 codewords[])
 {
        /* We require at least 2 possible symbols in the alphabet to produce a
@@ -350,14 +351,13 @@ try_building_tree_again:
        while (1) {
 
                /* Lowest frequency node. */
-               HuffmanNode *f1 = NULL;
+               HuffmanNode *f1;
 
                /* Second lowest frequency node. */
-               HuffmanNode *f2 = NULL;
+               HuffmanNode *f2;
 
-               /* Get the lowest and second lowest frequency nodes from
-                * the remaining leaves or from the intermediate nodes.
-                * */
+               /* Get the lowest and second lowest frequency nodes from the
+                * remaining leaves or from the intermediate nodes. */
 
                if (cur_leaf != end_leaf && (cur_inode == next_inode ||
                                        cur_leaf->freq <= cur_inode->freq)) {
@@ -371,11 +371,10 @@ try_building_tree_again:
                        f2 = (HuffmanNode*)cur_leaf++;
                } else if (cur_inode != next_inode) {
                        f2 = cur_inode++;
-               }
-
-               /* All nodes used up! */
-               if (f1 == NULL || f2 == NULL)
+               } else {
+                       /* All nodes used up! */
                        break;
+               }
 
                /* next_inode becomes the parent of f1 and f2. */