hashtable.h
Upload User: ykyjsl
Upload Date: 2022-01-30
Package Size: 145k
Code Size: 3k
Development Platform:

C/C++

  1. /******************************************************************************
  2. File: hashtable.h
  3. Authors:  John Carpinelli   (johnfc@ecr.mu.oz.au)
  4.   Wayne Salamonsen  (wbs@mundil.cs.mu.oz.au)
  5. Purpose: Data compression using a word-based model and revised 
  6. arithmetic coding method.
  7. Based on:  A. Moffat, R. Neal, I.H. Witten, "Arithmetic Coding Revisted",
  8. Proc. IEEE Data Compression Conference, Snowbird, Utah, 
  9. March 1995.
  10. Copyright 1995 John Carpinelli and Wayne Salamonsen, All Rights Reserved.
  11. These programs are supplied free of charge for research purposes only,
  12. and may not sold or incorporated into any commercial product.  There is
  13. ABSOLUTELY NO WARRANTY of any sort, nor any undertaking that they are
  14. fit for ANY PURPOSE WHATSOEVER.  Use them at your own risk.  If you do
  15. happen to find a bug, or have modifications to suggest, please report
  16. the same to Alistair Moffat, alistair@cs.mu.oz.au.  The copyright
  17. notice above and this statement of conditions must remain an integral
  18. part of each and every copy made of these files.
  19. ******************************************************************************/
  20. #ifndef HASHTABLE_H
  21. #define HASHTABLE_H
  22. #define MAXBUCKET 10 /* no. of words in each bucket */
  23. #define MAX_WORD_LEN  32 /* Maximum Word Length */
  24. #define STRINGBLOCK 1024 /* size of each block of words */
  25. #define GROWTH_RATE 2 /* growth on a bucket split */
  26. #define EXTRA_SYMBOLS 1  /* no. of extra symbols like ESCAPE */
  27. #define ALLOCATE_BLOCK 100 /* no. of buckets allocated at once */
  28. #define HASH_MULT 613
  29. #define HASH_MOD 1111151 /* a prime number */
  30. /*
  31. *
  32. * data structure to hold a string with a length byte.
  33. * Null terminated strings aren't used because non-word strings
  34. * may include multiple 's
  35. *
  36. */
  37. typedef struct {
  38.   unsigned char length; /* length of string */
  39.   unsigned char text[MAX_WORD_LEN]; /* characters of string */
  40. } string;
  41. /*
  42. *
  43. * data structure for holding blocks of words
  44. *
  45. */
  46. typedef struct string_block string_block;
  47. struct string_block {
  48.     int length;
  49.     unsigned char strings[STRINGBLOCK];
  50.     string_block *prev;
  51. };
  52. /*
  53.  * 
  54.  * dictionary data structures
  55.  *
  56.  */
  57. typedef struct {
  58.     unsigned char *pWord; /* pointer to word */
  59.     int wordNumber; /* ordinal word number */
  60. } word_rec;
  61. typedef struct {
  62.     int nBits; /* number of hash bits used */
  63.     int nWords; /* number of words in this bucket */
  64.     word_rec words[MAXBUCKET]; /* word records */
  65. } bucket;
  66. /*
  67.  * data structure for holding blocks of buckets
  68.  */
  69. typedef struct bucket_block bucket_block;
  70. struct bucket_block {
  71.     int nFreeBuckets;
  72.     bucket *pBuckets;
  73.     bucket_block *prev;
  74. };
  75. typedef struct {
  76.     int nBuckets; /* number of buckets in table */
  77.     int nBits; /* number of bits of key used */
  78.     int next_number; /* next available ordinal word no. */
  79.     bucket **pIndex; /* index to buckets */
  80.     string_block *pStrings; /* block of word/non-words */
  81.     unsigned char **pNumToWords; /* maps word nos to words */
  82.     int numToWordsLimit; /* current size of array */
  83.     bucket_block *pFreeBuckets; /* array of preallocated buckets */
  84. } hash_table;
  85. /*
  86.  *
  87.  * model interface functions
  88.  *
  89.  */
  90. hash_table *create_table(void);
  91. int lookup_word(string *pItem, hash_table *pTable);
  92. void get_word(hash_table *pTable, int symbol,
  93. unsigned char **pText, int *pLength);
  94. int add_word(string *pItem, hash_table *pTable);
  95. void purge_table(hash_table *pTable);
  96. #endif