/* FREQ.H - INTERFACE TO PROCEDURES FOR MAINTAINING FREQUENCIES. */


/* THE SET OF SYMBOLS THAT MAY BE ENCODED.  The actual symbols have codes
   from 0 up to No_of_symbols-1.  These symbols are re-ordered, and indexed 
   by integers from 1 to No_of_symbols. */

#define No_of_chars 256			/* Number of character symbols      */
#define EOF_symbol No_of_chars		/* Special EOF symbol               */

#define No_of_symbols (No_of_chars+1)	/* Total number of symbols          */


/* STRUCTURE HOLDING FREQUENCIES OF SYMBOLS IN A CONTEXT.  Frequencies and
   cumulative frequences are kept in arrays indexed by symbol indexes, which
   are meant to allow the most frequent symbols to appear at the front. */

typedef struct
{
  short symbol_to_index[No_of_symbols];	  /* Tables for translating between */
  short index_to_symbol[No_of_symbols+1]; /* symbols and indexes            */

  freq_value freq[No_of_symbols+1];	/* Symbol frequencies (freq[0]==0)  */
  freq_value cum_freq[No_of_symbols+1];	/* Cumulative symbol frequencies:   */
                                        /*   cum_freq[i] = sum of freq[j] 
                                               for j = i+1 to No_of_symbols */
} frequencies;


/* PROCEDURES. */

void initialize_frequencies  (frequencies *);
void update_frequencies (frequencies *, int);
