p2lzw / encode.h
encode.h
Raw
#ifndef AB1D5576_F986_4B13_AE08_ABCF50CDF907
#define AB1D5576_F986_4B13_AE08_ABCF50CDF907

#define HASH_SIZE 2048

#include "lzw.h"

// Data Structures
typedef struct EncodeEntry {
  struct EncodeEntry *next;
  int code;
  int prefix;
  unsigned char character;
} EncodeEntry;

// Encoder
void encode(int pruning, int maxBits);

// String Table
void initEncodeTable(EncodeEntry **hashTable, EncodeEntry **codeToEntry, int table_size);
void freeTable(EncodeEntry **hashTable, EncodeEntry **codeToEntry);
int pruneEncodeTable(EncodeEntry ***hashTable, EncodeEntry ***codeToEntry, int table_size);

// Hash
unsigned int hash(int prefix, unsigned char c);
void hashInsert(EncodeEntry **hashTable, EncodeEntry **codeToEntry, EncodeEntry *t);
EncodeEntry *hashFind(EncodeEntry **hashTable, int prefix, unsigned char c);

// Bit Packing
void bitPacker(int code);
void flushRemBits();

// Debugging
void printEncodeEntry(EncodeEntry* entry);
void dumpEncodeTable(EncodeEntry **hashTable, EncodeEntry **codeToEntry, int table_size);

#endif /* AB1D5576_F986_4B13_AE08_ABCF50CDF907 */