home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Arashi 1.1 Source / For your think c folder / Juri's Class Library / CStringDictionary.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-22  |  2.2 KB  |  76 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: CStringDictionary.h
  3.      Major release: Version 1.1, 7/22/92
  4.  
  5.      Last modification: Tuesday, June 22, 1993, 1:44
  6.      Created: Friday, December 4, 1992, 11:44
  7.  
  8.      Copyright © 1992-1993, Juri Munkki
  9. /*/
  10.  
  11. /*
  12. **    This class maintains a sort of dictionary of words. The idea
  13. **    is to have a fast way to find a dictionary word. A hashed
  14. **    table is used to speed up the searches while still keeping
  15. **    this class fairly simple.
  16. **
  17. **    NOTE:
  18. **        While data is being added to the object, the
  19. **        object can not be locked.
  20. */
  21. #pragma once
  22. #include "CBaseObject.h"
  23.  
  24. #define    DICTIONARYCLUMPSIZE        (16*sizeof(DictEntry))
  25. #define    WORDCLUMPSIZE            256
  26. #define HASHTABLESIZE            128    /* Must be a power of 2    */
  27.  
  28. /*
  29. **    The amount of storage required for a single item is
  30. **    determined by the token type. A tokentype of "short"
  31. **    will allow 32767 dictionary entries, which should be
  32. **    sufficient for the kinds of data that this class was
  33. **    written for.
  34. */
  35. typedef    short    tokentype;
  36.  
  37. /*
  38. **    Dictionary entries are stored into two separate handles.
  39. **    The other one is the list of words and the other one
  40. **    a list of hash table links and offsets to the words.
  41. */
  42. typedef struct
  43. {
  44.     long    nameOffset;
  45.     short    hashLink;
  46. } DictEntry;
  47.  
  48. class    CStringDictionary : public CBaseObject
  49. {
  50. public:
  51.                 /*    Variables:            */
  52.     short        dictCount;                //    Amount of dictionary entries.
  53.     long        logicalDictSize;        //    Used memory of dictionary handle.
  54.     long        realDictSize;            //    Actual size of dictionary handle.
  55.     DictEntry    **dictionary;            //    Handle to dictionary entries.
  56.     
  57.     long        logicalWordListSize;    //    Used memory of word list handle.
  58.     long        realWordListSize;        //    Actual size of word list handle.
  59.     unsigned char **wordList;            //    Word list.
  60.         
  61.     tokentype    hashTable[HASHTABLESIZE];    //    A hash table is used to accelerate lookups.
  62.  
  63.                 /*    Methods:            */    
  64.     void        IStringDictionary();
  65.     tokentype    AddDictEntry(unsigned char *entry, short len);
  66.     tokentype    FindEntry(unsigned char *entry, short len);
  67.     tokentype    SearchForEntry(unsigned char *entry, short len);
  68.     void        ReadFromStringList(short strListID);
  69.     
  70.     short        GetDictionarySize();
  71.     void        GetIndEntry(short index, StringPtr theEntry);
  72.     
  73.     void        Dispose();
  74.     void        Lock();
  75.     void        Unlock();
  76. };