man(1) Manual page archive


     HUFF(3)                                                   HUFF(3)

     NAME
          huff - huffman codebook/tree generator

     SYNOPSIS
          #include <huff.h>

          NODE *huff(inrout)
          int (*inrout)();

     DESCRIPTION
          Huff generates a binary Huffman codebook.  It obtains a list
          of messages one at a time from an input routine, inrout,
          declared as

               int inrout(str, p)
               char ** str;
               float *p;

          Inrout makes *str point to a null-terminated string identi-
          fying a message, and places in *p the (arbitrarily normal-
          ized) frequency of the message.  Inrout returns non-zero
          when data is returned and zero when there is no more data.

          Huff returns a pointer to a root of type NODE:

               typedef struct node {
                    char *datump;
                    struct node *to;
                    struct node *from;
                    struct node *ldad;
                    struct node *rdad;
                    struct node *kid;
                    float prob;
               } NODE;

          The root heads a linked list and the Huffman tree.  The dou-
          bly linked list, connected via from and to, is ordered as
          the codebook was generated.  The tree is connected via kid,
          ldad, and rdad, with null pointers at the various ends.  The
          kid field points towards the root, ldad and rdad point away:
          node->ldad->kid==node and node->rdad->kid==node.  the datump
          field is null or points to a message identifier.

          The codeword for a message may be read off from the path
          from the root to the node containing the message identifier,
          counting ldad branches as 0 and rdad branches as 1.

     BUGS
          A code with only one message dumps core.

     HUFF(3)                                                   HUFF(3)