Leaked source code of windows server 2003
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.

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