Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

140 lines
2.5 KiB

  1. #ifndef _SPANISH_DICT_H_
  2. #define _SPANISH_DICT_H_
  3. #include "trie.h"
  4. #include "SpanishUtils.h"
  5. #include "VarArray.h"
  6. #define DICT_4_INIT_SIZE 5400 // base on the current dictionary size.
  7. #define DICT_8_INIT_SIZE 12100
  8. #define DICT_STR_INIT_SIZE 400
  9. struct CompressDictItem4
  10. {
  11. int Compare(CompressDictItem4 & item)
  12. {
  13. return ulStr - item.ulStr;
  14. }
  15. ULONG ulStr;
  16. ULONG ulData;
  17. };
  18. struct CompressDictItem8
  19. {
  20. int Compare(CompressDictItem8 & item)
  21. {
  22. if (ullStr > item.ullStr)
  23. {
  24. return 1;
  25. }
  26. else if (ullStr < item.ullStr)
  27. {
  28. return -1;
  29. }
  30. return 0;
  31. }
  32. ULONGLONG ullStr;
  33. ULONG ulData;
  34. };
  35. struct CompressDictItemStr
  36. {
  37. CompressDictItemStr() :
  38. pszStr(NULL),
  39. ulData(0)
  40. {
  41. }
  42. ~CompressDictItemStr()
  43. {
  44. delete[] pszStr;
  45. }
  46. int Compare(CompressDictItemStr& item)
  47. {
  48. return g_apSpanishUtil->aiStrcmp(pszStr, item.pszStr);
  49. }
  50. unsigned char* pszStr;
  51. ULONG ulData;
  52. };
  53. struct PsudoCompressDictItemStr : public CompressDictItemStr
  54. {
  55. ~PsudoCompressDictItemStr()
  56. {
  57. pszStr = NULL; // we don't own the memory
  58. }
  59. };
  60. template<class T>
  61. T* BinaryFind(T* Array, ULONG ulArraySize, T& ItemToFind)
  62. {
  63. Assert(ulArraySize);
  64. LONG lStart = 0;
  65. LONG lEnd = ulArraySize - 1;
  66. T* pCurrItem;
  67. while(lEnd >= lStart)
  68. {
  69. ULONG lCurrIndex = (lEnd + lStart) / 2;
  70. pCurrItem = &(Array[lCurrIndex]);
  71. int iRet = pCurrItem->Compare(ItemToFind);
  72. if (0 == iRet)
  73. {
  74. return pCurrItem;
  75. }
  76. else if (iRet > 0)
  77. {
  78. lEnd = lCurrIndex - 1;
  79. }
  80. else
  81. {
  82. lStart = lCurrIndex + 1;
  83. }
  84. }
  85. return NULL;
  86. }
  87. class CSpanishDict
  88. {
  89. public:
  90. CSpanishDict(WCHAR* pwcsInitFilePath);
  91. void BreakWord(
  92. ULONG ulLen,
  93. WCHAR* pwcsWord,
  94. bool* pfExistAlt,
  95. ULONG* pulAltLen,
  96. WCHAR* pwcsAlt);
  97. private:
  98. //
  99. // methods
  100. //
  101. bool Find(WCHAR* pwcs, ULONG ulLen, ULONG& ulData);
  102. private:
  103. //
  104. // members
  105. //
  106. ULONG m_ulDictItem4Count;
  107. CVarArray<CompressDictItem4> m_vaDictItem4;
  108. ULONG m_ulDictItem8Count;
  109. CVarArray<CompressDictItem8> m_vaDictItem8;
  110. ULONG m_ulDictItemStrCount;
  111. CVarArray<CompressDictItemStr> m_vaDictItemStr;
  112. CAutoClassPointer<CSpanishSuffixDict> m_apSpanishSuffix;
  113. };
  114. #endif // _SPANISH_DICT_H_