00001 #ifndef MMANN_AGENERICHASH_H 00002 #define MMANN_AGENERICHASH_H 00003 00011 00013 static const int HashPrimesList[] = { 00014 257, 00015 293, 00016 331, 00017 367, 00018 409, 00019 461, 00020 521, 00021 587, 00022 653, 00023 739, 00024 827, 00025 929, 00026 1049, 00027 1181, 00028 1321, 00029 1487, 00030 1693, 00031 1879, 00032 2113, 00033 2377, 00034 2677, 00035 3011, 00036 3389, 00037 3821, 00038 4283, 00039 4813, 00040 5417, 00041 6091, 00042 6857, 00043 7717, 00044 8677, 00045 9767, 00046 10973, 00047 12343, 00048 13901, 00049 15629, 00050 17573, 00051 19777, 00052 22247, 00053 25031, 00054 28151, 00055 31663, 00056 35671, 00057 40087, 00058 45083, 00059 50723, 00060 57059, 00061 64187, 00062 72211, 00063 81239, 00064 91393, 00065 102829, 00066 115663, 00067 130121, 00068 146389, 00069 164683, 00070 185291, 00071 208433, 00072 234499, 00073 263803, 00074 296767, 00075 333857, 00076 375593, 00077 422537, 00078 475367, 00079 534799, 00080 601631, 00081 676829, 00082 761429, 00083 856627, 00084 963689, 00085 1084133, 00086 1219649, 00087 1372109, 00088 1543631, 00089 1736599, 00090 1953659, 00091 2197847, 00092 2472577, 00093 2781677, 00094 3129383, 00095 3520519, 00096 3960587, 00097 4455667, 00098 5012627, 00099 5639191, 00100 6344087, 00101 7137101, 00102 8029243, 00103 9032887, 00104 10161997, 00105 11432249, 00106 12861281, 00107 14468933, 00108 16277561, 00109 18312263, 00110 20601271, 00111 23176429, 00112 26073497, 00113 29332687, 00114 32999269, 00115 37124167, 00116 41764741, 00117 46985261, 00118 52858427, 00119 59465723, 00120 66898963, 00121 75261311, 00122 84668971, 00123 95252603, 00124 107159153, 00125 120554059, 00126 135623317, 00127 152576233, 00128 171648317, 00129 193104269, 00130 217242323, 00131 244397591, 00132 274947317, 00133 309315703, 00134 347980163, 00135 391477727, 00136 440412409, 00137 495463937, 00138 557396929, 00139 627071569, 00140 705455519, 00141 793637437, 00142 892842107, 00143 1004447359, 00144 1130003291, 00145 1271253703, 00146 1430160409, 00147 1608930451, 00148 1810046779, 00149 2036302607, 00150 -1 00151 }; 00152 00154 #define NUM_PRIMES sizeof(HashPrimesList)-1 00155 00160 inline int FindClosestPrime(int Number) 00161 { 00162 int i; 00163 00164 for(i=0;i<NUM_PRIMES;i++) 00165 if (HashPrimesList[i] > Number) 00166 break; 00167 00168 return HashPrimesList[i]; 00169 } 00170 00172 enum DeleteHashDataEnum {NO_DELETE_HASH_ITEM, DELETE_HASH_ITEM, DELETE_HASH_ITEM_ARRAY}; 00173 00175 template <class Key, class ConfigData> 00176 class AGenericHash 00177 { 00178 public: 00180 virtual ~AGenericHash(); 00181 00187 virtual Key* Insert(Key* key, bool OptimizeForCaching) = 0; 00188 00190 virtual void DeleteItems(); 00191 00192 protected: 00194 AGenericHash(int SizeWanted, ACompareNodesAlgorithm<Key, ConfigData>* Compare, 00195 AHashAlgorithm<Key>* Hash, 00196 DeleteHashDataEnum DeleteHashData = NO_DELETE_HASH_ITEM); 00197 00201 virtual void Copy(AGenericHash<Key, ConfigData>* Hash); 00202 00204 int m_Size; 00205 00207 int m_NumberOfElements; 00208 00210 ACompareNodesAlgorithm<Key, ConfigData>* m_Compare; 00211 00213 AHashAlgorithm<Key>* m_Hash; 00214 00216 DeleteHashDataEnum m_DeleteHashData; 00217 00218 }; 00219 00220 template <class Key,class ConfigData> 00221 AGenericHash<Key, ConfigData>::AGenericHash(int SizeWanted, 00222 ACompareNodesAlgorithm<Key, ConfigData>* Compare, 00223 AHashAlgorithm<Key>* Hash, 00224 DeleteHashDataEnum DeleteHashData) 00225 { 00226 m_Size = SizeWanted; 00227 m_NumberOfElements = 0; 00228 m_Compare = Compare; 00229 m_Hash = Hash; 00230 m_DeleteHashData = DeleteHashData; 00231 } 00232 00233 template <class Key, class ConfigData> 00234 AGenericHash<Key, ConfigData>::~AGenericHash() 00235 { 00236 } 00237 00238 template <class Key, class ConfigData> 00239 void AGenericHash<Key, ConfigData>::DeleteItems() 00240 { 00241 } 00242 00243 00244 template <class Key, class ConfigData> 00245 void AGenericHash<Key, ConfigData>::Copy(AGenericHash<Key, ConfigData>* Hash) 00246 { 00247 m_Size = Hash->m_Size; 00248 m_NumberOfElements = Hash->m_NumberOfElements; 00249 m_Compare = Hash->m_Compare; 00250 m_Hash = Hash->m_Hash; 00251 m_DeleteHashData = Hash->m_DeleteHashData; 00252 } 00253 00254 #endif