/*
 * CT_MALLOC_OVERHEAD is some constant based on either the
 * malloc implementation (generally platform-dependent) or a good
 * guess. "64" is a good guess, according to mark eichin (eichin@mit.edu)
 */
#define CT_MALLOC_OVERHEAD 64
#define CT_INITIAL_NUMBER_TABLE_ELTS 64

struct s_ct_elt {
  int           car;
  int           cdr;
  unsigned long len;
};

typedef struct s_ct_elt ct_elt;

#define CT_ELT_TYPE ct_elt

struct s_codetab {
  unsigned int  rootsize;   /* LZW stuff */
  unsigned int  codesize;   /* LZW stuff */
  unsigned int  blocksize;  /* LZW stuff */
  unsigned int  clearcode;  /* LZW stuff */
  unsigned int  endofinfo;  /* LZW stuff */

  /* 
   * these fields manage a dynamically scoped array which is realloc()'ed
   * as necessary with ((2^n) - CT_MALLOC_OVERHEAD) bytes, where "n" is
   * as small as possible given the current number of elements
   */
  unsigned int  allocpower; /* the current "n" of the realloc scheme */
  /* allocpower may not do anything at this point. We'll see. */
  unsigned int  allocbytes; /* the current number of bytes allocated */
  unsigned int  currentmax; /* the number of elements the codetable
			       can currently contain */

  unsigned int  nextentry;  /* an array offset indicating the next empty
			       entry */
  CT_ELT_TYPE   *table;      /* the table (array) pointer (duh) */
};

typedef struct s_codetab codetab;
  
void ct_preinitialize (codetab* ct);
void ct_makeroomfor (codetab* ct, int elts);
int ct_append (codetab* ct, int car, int cdr);
void ct_seed(codetab *ct, int ct_length);

#define elt_length(x) (x).len
