home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 2.0 / Internet Publisher's Toolbox.iso / internet / ntserver / wtsource / trie.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-16  |  1.2 KB  |  55 lines

  1.  
  2. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  3.  
  4. #ifndef TRIE_H
  5. #define TRIE_H
  6. #include "cdialect.h"
  7. /*
  8.   Trie implementation of dictionary
  9.   */
  10.  
  11. #define ALPHA_SIZE 37
  12. #define CHUNK_SIZE 4096 /* allocate CHUNK_SIZE units at a time */
  13. #define MAX_BLOCKS 4096 /* maximum number of blocks to hold (maybe realloc)*/
  14.  
  15.  
  16. typedef struct _dict_data {
  17.   int next_block;
  18.   int num_occur;
  19. } dict_data;
  20.  
  21. typedef struct _trie {
  22.   char *string;
  23.   void *datum;
  24.   struct _trie **table;
  25. } trie;
  26.  
  27. typedef struct _allocator {
  28.   char* tofree[MAX_BLOCKS];
  29.   int blocks_allocated;
  30.   char* next_location;
  31.   int items_left;
  32.   int size;
  33.   void (*dispose)();
  34. } allocator;
  35.  
  36. typedef struct _trie_allocator {
  37.   allocator* tries;
  38.   allocator* trie_tables;
  39. } trie_allocator;
  40.  
  41. char* fast_alloc _AP((allocator* x));
  42. void  fast_free _AP((allocator* x));
  43. allocator* make_allocator _AP((int item_size,void (*dispose)(char *item)));
  44. trie_allocator* make_trie_allocator();
  45.  
  46. typedef trie *trie_table[ALPHA_SIZE];
  47.  
  48. void **trie_lookup _AP((char* key, trie* dict,trie_allocator* addp));
  49. trie *new_trie _AP((char* word,trie_allocator* alloc));
  50. int encode _AP((unsigned char* word));
  51.  
  52. extern trie* load_dict _AP((FILE* stream,trie_allocator *alloc));
  53.  
  54. #endif
  55.