/tests/CompilerOptionsTests/testCpreprocessorOption/data_hash.C

https://bitbucket.org/bathtub/rose · C · 372 lines · 243 code · 85 blank · 44 comment · 95 complexity · 50ae2d276020d04df5363519411cc34c MD5 · raw file

  1. // DQ (12/5/2007): A++ does not compile with g++ version 4 and greater so the source
  2. // code has been modified to skip the code when:
  3. #if ( (__GNUC__ == 3) && (__GNUC_MINOR__ <= 4) )
  4. // GNU will build intances of all objects in the header file if this
  5. // is not specified. The result is very large object files (too many symbols)
  6. // so we can significantly reduce the size of the object files which will
  7. // build the library (factor of 5-10).
  8. #ifdef GNU
  9. #pragma implementation "data_hash.h"
  10. #endif
  11. #include "A++.h"
  12. bool doubleArray_Data_Hash_Table::USE_HASH_TABLE_FOR_ARRAY_DATA_STORAGE = false;
  13. int doubleArray_Data_Hash_Table::Hash_Table_Hits = 0;
  14. int doubleArray_Data_Hash_Table::Hash_Table_Misses = 0;
  15. doubleArray_Data_Hash_Table::~doubleArray_Data_Hash_Table()
  16. {
  17. }
  18. doubleArray_Data_Hash_Table::doubleArray_Data_Hash_Table()
  19. {
  20. if (APP_DEBUG > 0)
  21. printf ("Initialize the doubleArray_Data_hash table! \n");
  22. Number_Of_Buckets = NUMBER_OF_BUCKETS;
  23. Depth_Of_Table = HASH_TABLE_DEPTH;
  24. // Hash_Table_Hits = 0;
  25. // Hash_Table_Misses = 0;
  26. // Initialize the Search table (hash_table)!
  27. int i;
  28. for (i=0; i < Number_Of_Buckets; i++)
  29. for (int j=0; j < Depth_Of_Table; j++)
  30. Search_Table [i][j] = NULL;
  31. // This stores the largest i n d e x position that is currently
  32. // in use in the search table for each Bucket in the hash table!
  33. for (i=0; i < Number_Of_Buckets; i++)
  34. Max_Index_In_Table [i] = 0;
  35. if (APP_DEBUG > 0)
  36. printf ("Leaving Hash_Table constructor! \n");
  37. }
  38. double* doubleArray_Data_Hash_Table::Get_Primative_Array ( int Size )
  39. {
  40. int Key = Size;
  41. int Hash_Table_Key = Key % Number_Of_Buckets;
  42. int Index = -1;
  43. double_Hashed_Array_Type *Temp_Bucket = NULL;
  44. do {
  45. Index++;
  46. Temp_Bucket = Search_Table [Hash_Table_Key][Index];
  47. }
  48. while ( (Index < Max_Index_In_Table [Hash_Table_Key]) &&
  49. ( (Temp_Bucket == NULL) || ( (Temp_Bucket != NULL) && (Temp_Bucket->Memory_Size != Key) ) ) );
  50. if ( (Index == Depth_Of_Table-1) && ( (Temp_Bucket != NULL ) && ( Temp_Bucket->Memory_Size != Key ) ) )
  51. {
  52. printf ("ERROR:Get_Temporary_Vector - Not yet implemented, 2nd level of hash table! \n");
  53. APP_ABORT();
  54. }
  55. if (Temp_Bucket == NULL)
  56. {
  57. // If we can't find what what we need then we should build it!
  58. Temp_Bucket = new double_Hashed_Array_Type ( Size ); // Set to the desired length!
  59. Hash_Table_Misses++;
  60. }
  61. else
  62. {
  63. Search_Table [Hash_Table_Key][Index] = NULL;
  64. // Now we have to the positions farther down the table to
  65. // a position one back. So that the next search will not prematurly
  66. // find a NULL pointer before getting to the end of the list!
  67. Hash_Table_Hits++;
  68. }
  69. // Error checking
  70. if (Temp_Bucket->Memory_Size != Key)
  71. {
  72. // printf ("NOTE: Get_Primative_Array: Temp_Bucket->Memory_Size() != Key (input size) (Redimensioning) \n");
  73. Temp_Bucket->redim(Key); // Set to the desired length!
  74. // Record this as a MISS!
  75. Hash_Table_Misses++;
  76. Hash_Table_Hits--;
  77. }
  78. return Temp_Bucket->Raw_Memory;
  79. }
  80. void doubleArray_Data_Hash_Table::Put_Primative_Array_Into_Storage ( double* Memory_To_Store, int Size )
  81. {
  82. int Key = Size;
  83. int Hash_Table_Key = Key % Number_Of_Buckets;
  84. int Index = -1;
  85. double_Hashed_Array_Type *Temp_Bucket = NULL;
  86. double_Hashed_Array_Type *New_Bucket = new double_Hashed_Array_Type ( Memory_To_Store , Size );
  87. do {
  88. Index++;
  89. Temp_Bucket = Search_Table [Hash_Table_Key][Index];
  90. }
  91. while ( (Index < Depth_Of_Table-1) && (Temp_Bucket != NULL ) );
  92. if ( (Index == Depth_Of_Table-1) && (Temp_Bucket != NULL ) )
  93. {
  94. printf ("ERROR:Put_Primative_Memory_Into_Storage - Not yet implemented, 2nd level of hash table! \n");
  95. APP_ABORT();
  96. }
  97. Max_Index_In_Table [Hash_Table_Key] = (Max_Index_In_Table [Hash_Table_Key] < Index) ? Index : Max_Index_In_Table [Hash_Table_Key];
  98. if ( Temp_Bucket == NULL )
  99. {
  100. Search_Table [Hash_Table_Key][Index] = New_Bucket;
  101. }
  102. }
  103. bool floatArray_Data_Hash_Table::USE_HASH_TABLE_FOR_ARRAY_DATA_STORAGE = FALSE;
  104. int floatArray_Data_Hash_Table::Hash_Table_Hits = 0;
  105. int floatArray_Data_Hash_Table::Hash_Table_Misses = 0;
  106. floatArray_Data_Hash_Table::~floatArray_Data_Hash_Table()
  107. {
  108. }
  109. floatArray_Data_Hash_Table::floatArray_Data_Hash_Table()
  110. {
  111. if (APP_DEBUG > 0)
  112. printf ("Initialize the floatArray_Data_hash table! \n");
  113. Number_Of_Buckets = NUMBER_OF_BUCKETS;
  114. Depth_Of_Table = HASH_TABLE_DEPTH;
  115. // Hash_Table_Hits = 0;
  116. // Hash_Table_Misses = 0;
  117. // Initialize the Search table (hash_table)!
  118. int i;
  119. for (i=0; i < Number_Of_Buckets; i++)
  120. for (int j=0; j < Depth_Of_Table; j++)
  121. Search_Table [i][j] = NULL;
  122. // This stores the largest i n d e x position that is currently
  123. // in use in the search table for each Bucket in the hash table!
  124. for (i=0; i < Number_Of_Buckets; i++)
  125. Max_Index_In_Table [i] = 0;
  126. if (APP_DEBUG > 0)
  127. printf ("Leaving Hash_Table constructor! \n");
  128. }
  129. float* floatArray_Data_Hash_Table::Get_Primative_Array ( int Size )
  130. {
  131. int Key = Size;
  132. int Hash_Table_Key = Key % Number_Of_Buckets;
  133. int Index = -1;
  134. float_Hashed_Array_Type *Temp_Bucket = NULL;
  135. do {
  136. Index++;
  137. Temp_Bucket = Search_Table [Hash_Table_Key][Index];
  138. }
  139. while ( (Index < Max_Index_In_Table [Hash_Table_Key]) &&
  140. ( (Temp_Bucket == NULL) || ( (Temp_Bucket != NULL) && (Temp_Bucket->Memory_Size != Key) ) ) );
  141. if ( (Index == Depth_Of_Table-1) && ( (Temp_Bucket != NULL ) && ( Temp_Bucket->Memory_Size != Key ) ) )
  142. {
  143. printf ("ERROR:Get_Temporary_Vector - Not yet implemented, 2nd level of hash table! \n");
  144. APP_ABORT();
  145. }
  146. if (Temp_Bucket == NULL)
  147. {
  148. // If we can't find what what we need then we should build it!
  149. Temp_Bucket = new float_Hashed_Array_Type ( Size ); // Set to the desired length!
  150. Hash_Table_Misses++;
  151. }
  152. else
  153. {
  154. Search_Table [Hash_Table_Key][Index] = NULL;
  155. // Now we have to the positions farther down the table to
  156. // a position one back. So that the next search will not prematurly
  157. // find a NULL pointer before getting to the end of the list!
  158. Hash_Table_Hits++;
  159. }
  160. // Error checking
  161. if (Temp_Bucket->Memory_Size != Key)
  162. {
  163. // printf ("NOTE: Get_Primative_Array: Temp_Bucket->Memory_Size() != Key (input size) (Redimensioning) \n");
  164. Temp_Bucket->redim(Key); // Set to the desired length!
  165. // Record this as a MISS!
  166. Hash_Table_Misses++;
  167. Hash_Table_Hits--;
  168. }
  169. return Temp_Bucket->Raw_Memory;
  170. }
  171. void floatArray_Data_Hash_Table::Put_Primative_Array_Into_Storage ( float* Memory_To_Store, int Size )
  172. {
  173. int Key = Size;
  174. int Hash_Table_Key = Key % Number_Of_Buckets;
  175. int Index = -1;
  176. float_Hashed_Array_Type *Temp_Bucket = NULL;
  177. float_Hashed_Array_Type *New_Bucket = new float_Hashed_Array_Type ( Memory_To_Store , Size );
  178. do {
  179. Index++;
  180. Temp_Bucket = Search_Table [Hash_Table_Key][Index];
  181. }
  182. while ( (Index < Depth_Of_Table-1) && (Temp_Bucket != NULL ) );
  183. if ( (Index == Depth_Of_Table-1) && (Temp_Bucket != NULL ) )
  184. {
  185. printf ("ERROR:Put_Primative_Memory_Into_Storage - Not yet implemented, 2nd level of hash table! \n");
  186. APP_ABORT();
  187. }
  188. Max_Index_In_Table [Hash_Table_Key] = (Max_Index_In_Table [Hash_Table_Key] < Index) ? Index : Max_Index_In_Table [Hash_Table_Key];
  189. if ( Temp_Bucket == NULL )
  190. {
  191. Search_Table [Hash_Table_Key][Index] = New_Bucket;
  192. }
  193. }
  194. bool intArray_Data_Hash_Table::USE_HASH_TABLE_FOR_ARRAY_DATA_STORAGE = FALSE;
  195. int intArray_Data_Hash_Table::Hash_Table_Hits = 0;
  196. int intArray_Data_Hash_Table::Hash_Table_Misses = 0;
  197. intArray_Data_Hash_Table::~intArray_Data_Hash_Table()
  198. {
  199. }
  200. intArray_Data_Hash_Table::intArray_Data_Hash_Table()
  201. {
  202. if (APP_DEBUG > 0)
  203. printf ("Initialize the intArray_Data_hash table! \n");
  204. Number_Of_Buckets = NUMBER_OF_BUCKETS;
  205. Depth_Of_Table = HASH_TABLE_DEPTH;
  206. // Hash_Table_Hits = 0;
  207. // Hash_Table_Misses = 0;
  208. // Initialize the Search table (hash_table)!
  209. int i;
  210. for (i=0; i < Number_Of_Buckets; i++)
  211. for (int j=0; j < Depth_Of_Table; j++)
  212. Search_Table [i][j] = NULL;
  213. // This stores the largest i n d e x position that is currently
  214. // in use in the search table for each Bucket in the hash table!
  215. for (i=0; i < Number_Of_Buckets; i++)
  216. Max_Index_In_Table [i] = 0;
  217. if (APP_DEBUG > 0)
  218. printf ("Leaving Hash_Table constructor! \n");
  219. }
  220. int* intArray_Data_Hash_Table::Get_Primative_Array ( int Size )
  221. {
  222. int Key = Size;
  223. int Hash_Table_Key = Key % Number_Of_Buckets;
  224. int Index = -1;
  225. int_Hashed_Array_Type *Temp_Bucket = NULL;
  226. do {
  227. Index++;
  228. Temp_Bucket = Search_Table [Hash_Table_Key][Index];
  229. }
  230. while ( (Index < Max_Index_In_Table [Hash_Table_Key]) &&
  231. ( (Temp_Bucket == NULL) || ( (Temp_Bucket != NULL) && (Temp_Bucket->Memory_Size != Key) ) ) );
  232. if ( (Index == Depth_Of_Table-1) && ( (Temp_Bucket != NULL ) && ( Temp_Bucket->Memory_Size != Key ) ) )
  233. {
  234. printf ("ERROR:Get_Temporary_Vector - Not yet implemented, 2nd level of hash table! \n");
  235. APP_ABORT();
  236. }
  237. if (Temp_Bucket == NULL)
  238. {
  239. // If we can't find what what we need then we should build it!
  240. Temp_Bucket = new int_Hashed_Array_Type ( Size ); // Set to the desired length!
  241. Hash_Table_Misses++;
  242. }
  243. else
  244. {
  245. Search_Table [Hash_Table_Key][Index] = NULL;
  246. // Now we have to the positions farther down the table to
  247. // a position one back. So that the next search will not prematurly
  248. // find a NULL pointer before getting to the end of the list!
  249. Hash_Table_Hits++;
  250. }
  251. // Error checking
  252. if (Temp_Bucket->Memory_Size != Key)
  253. {
  254. // printf ("NOTE: Get_Primative_Array: Temp_Bucket->Memory_Size() != Key (input size) (Redimensioning) \n");
  255. Temp_Bucket->redim(Key); // Set to the desired length!
  256. // Record this as a MISS!
  257. Hash_Table_Misses++;
  258. Hash_Table_Hits--;
  259. }
  260. return Temp_Bucket->Raw_Memory;
  261. }
  262. void intArray_Data_Hash_Table::Put_Primative_Array_Into_Storage ( int* Memory_To_Store, int Size )
  263. {
  264. int Key = Size;
  265. int Hash_Table_Key = Key % Number_Of_Buckets;
  266. int Index = -1;
  267. int_Hashed_Array_Type *Temp_Bucket = NULL;
  268. int_Hashed_Array_Type *New_Bucket = new int_Hashed_Array_Type ( Memory_To_Store , Size );
  269. do {
  270. Index++;
  271. Temp_Bucket = Search_Table [Hash_Table_Key][Index];
  272. }
  273. while ( (Index < Depth_Of_Table-1) && (Temp_Bucket != NULL ) );
  274. if ( (Index == Depth_Of_Table-1) && (Temp_Bucket != NULL ) )
  275. {
  276. printf ("ERROR:Put_Primative_Memory_Into_Storage - Not yet implemented, 2nd level of hash table! \n");
  277. APP_ABORT();
  278. }
  279. Max_Index_In_Table [Hash_Table_Key] = (Max_Index_In_Table [Hash_Table_Key] < Index) ? Index : Max_Index_In_Table [Hash_Table_Key];
  280. if ( Temp_Bucket == NULL )
  281. {
  282. Search_Table [Hash_Table_Key][Index] = New_Bucket;
  283. }
  284. }
  285. // DQ (12/5/2007): A++ does not compile with g++ version 4 and greater so the source
  286. // code has been modified to skip the code when ( (__GNUC__ == 3) && (__GNUC_MINOR__ <= 4) )
  287. #endif