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.

187 lines
4.4 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (C) 1997, Microsoft Corporation. All Rights Reserved.
  4. //
  5. // Hash.h :
  6. //
  7. // Owner : ChaeSeong Lim, HET MSCH RND (e-mail:[email protected])
  8. //
  9. // History : 1996/May
  10. /////////////////////////////////////////////////////////////////////////////
  11. #ifndef __HASH_H__
  12. #define __HASH_H__
  13. #if !defined (_UNICODE) && !defined (_MBCS)
  14. #error _UNICODE or _MBCS is required.
  15. #endif
  16. #include <tchar.h>
  17. #define OYONG_HASHSIZE 5501 // current num of words = 3657
  18. /////////////////////////////////////////////////////////////////////////////
  19. // CHash
  20. class CHash {
  21. public:
  22. // Constructor
  23. CHash() {}
  24. // Attributes
  25. // Operations
  26. virtual void Add(LPCTSTR) {}
  27. virtual BOOL Find(LPCTSTR) { return FALSE; }
  28. virtual void Delete(LPCTSTR) {}
  29. // Implementations
  30. protected:
  31. virtual UINT Hash(const _TXCHAR *key); // UINT = 32 bit unsigned
  32. public:
  33. // Destructor
  34. virtual ~CHash() { }
  35. };
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CHash inline fuctions
  38. // Hash fuction
  39. inline UINT CHash::Hash(const _TXCHAR *key)
  40. {
  41. UINT hashValue = 0, g;
  42. while (*key) {
  43. hashValue = (hashValue << 4) + *key++;
  44. if (g = hashValue & 0xF0000000) {
  45. hashValue ^= g >> 24;
  46. hashValue &= ~g;
  47. }
  48. }
  49. return hashValue % OYONG_HASHSIZE;
  50. }
  51. #ifdef _DIC_BUILD_
  52. /////////////////////////////////////////////////////////////////////////////
  53. // CMemHash inline fuctions
  54. class COyongMakeHash : public CHash {
  55. public:
  56. // Constructor
  57. COyongMakeHash() {
  58. for (int i=0; i<OYONG_HASHSIZE; i++) bufArray[i] = 0;
  59. }
  60. struct CElement {
  61. CElement(LPCTSTR _incorrectStr, LPCTSTR _correctStr, BYTE _pumsa) {
  62. incorrectStr = _incorrectStr;
  63. correctStr[0] = _correctStr;
  64. Pumsa[0] = _pumsa;
  65. numOfCorrectStr = 1;
  66. }
  67. void Append(LPCTSTR _correctStr, BYTE _pumsa) {
  68. correctStr[numOfCorrectStr] = _correctStr;
  69. Pumsa[numOfCorrectStr] = _pumsa;
  70. numOfCorrectStr++;
  71. }
  72. CString incorrectStr;
  73. BYTE numOfCorrectStr;
  74. CString correctStr[10]; // Max # of correct strings is 10
  75. BYTE Pumsa[10];
  76. };
  77. // Attributes
  78. // Operations
  79. void Add(LPCTSTR incorrectStr, LPCTSTR correctStr, BYTE pumsa);
  80. void WriteDict(HANDLE hOut);
  81. //BOOL Find(LPCTSTR);
  82. // Implementations
  83. protected:
  84. CElement *bufArray[OYONG_HASHSIZE];
  85. public:
  86. // Destructor
  87. ~COyongMakeHash();
  88. };
  89. #endif // _DIC_BUILD_
  90. /////////////////////////////////////////////////////////////////////////////
  91. // COyongHash Class
  92. class COyongHash : public CHash {
  93. public:
  94. // Constructor
  95. COyongHash(HANDLE hDict, UINT hashSize, UINT bufferSize);
  96. COyongHash() {}
  97. // Attributes
  98. // Operations
  99. //void Add(LPCTSTR);
  100. BOOL Find(LPCTSTR searchWord, BYTE pumsa, LPTSTR correctWord);
  101. // Implementations
  102. protected:
  103. UINT m_hashSize, m_bufferSize;
  104. WORD *m_lpHashTable;
  105. char *m_lpBuf;
  106. public:
  107. // Destructor
  108. ~COyongHash();
  109. };
  110. #define WORD_HASH_SIZE 2003// 1009, 2003, 4007
  111. /////////////////////////////////////////////////////////////////////////////
  112. // COyongHash Class
  113. class CWordHash : public CHash {
  114. public:
  115. // Constructor
  116. CWordHash() {}
  117. // Attributes
  118. // Operations
  119. //void Add(LPCTSTR);
  120. BOOL Find(LPCTSTR searchWord, BYTE *pumsa);
  121. void Add(LPCTSTR searchWord, BYTE pumsa);
  122. // Implementations
  123. protected:
  124. UINT Hash(const _TXCHAR *key); // UINT = 32 bit unsigned
  125. static BYTE m_lpHashTable[WORD_HASH_SIZE][20];
  126. public:
  127. // Destructor
  128. ~CWordHash() {}
  129. };
  130. // Hash fuction
  131. inline
  132. UINT CWordHash::Hash(const _TXCHAR *key)
  133. {
  134. UINT hashValue = 0, g;
  135. while (*key) {
  136. hashValue = (hashValue << 4) + *key++;
  137. if (g = hashValue & 0xF0000000) {
  138. hashValue ^= g >> 24;
  139. hashValue &= ~g;
  140. }
  141. }
  142. return hashValue % WORD_HASH_SIZE;
  143. }
  144. inline
  145. void CWordHash::Add(LPCTSTR searchWord, BYTE pumsa)
  146. {
  147. UINT hashVal = CWordHash::Hash((const _TXCHAR*)searchWord);
  148. memset(m_lpHashTable[hashVal], '\0', 20);
  149. _tcscpy((LPTSTR)m_lpHashTable[hashVal], searchWord);
  150. m_lpHashTable[hashVal][19] = pumsa;
  151. }
  152. #endif // !__HASH_H__