diff options
Diffstat (limited to 'huffman.c')
-rw-r--r-- | huffman.c | 51 |
1 files changed, 43 insertions, 8 deletions
@@ -3,13 +3,52 @@ #include "nmglobal.h" #include "nbench1.h" + +/************************ +** HUFFMAN COMPRESSION ** +************************/ + +/* +** DEFINES +*/ +#define EXCLUDED 32000L /* Big positive value */ + +/* +** TYPEDEFS +*/ +typedef struct { + unsigned char c; /* Byte value */ + float freq; /* Frequency */ + int parent; /* Parent node */ + int left; /* Left pointer = 0 */ + int right; /* Right pointer = 1 */ +} huff_node; + +/* +** GLOBALS +*/ +static huff_node *hufftree; /* The huffman tree */ +static long plaintextlen; /* Length of plaintext */ + +/* +** PROTOTYPES +*/ +static void create_text_line(char *dt,long nchars); +static void create_text_block(char *tb, unsigned long tblen, + unsigned short maxlinlen); +static unsigned long DoHuffIteration(char *plaintext, + char *comparray, char *decomparray, + unsigned long arraysize, unsigned long nloops, huff_node *hufftree); +static void SetCompBit(uint8_t *comparray, uint32_t bitoffset, char bitchar); +static int GetCompBit(uint8_t *comparray, uint32_t bitoffset); + /* ** Word catalog */ #define WORDCATSIZE 50 -char *wordcatarray[WORDCATSIZE] = -{ "Hello", +char *wordcatarray[WORDCATSIZE] = { /* FIXME: const? */ + "Hello", "He", "Him", "the", @@ -58,12 +97,8 @@ char *wordcatarray[WORDCATSIZE] = "used", "shown", "you", - "know" }; - - -/************************ -** HUFFMAN COMPRESSION ** -************************/ + "know" +}; /************** ** DoHuffman ** |