| … | … | @@ -30,6 +30,8 @@ |
| 30 | 30 | * This is LANL Copyright Disclosure C14043/LA-CC-14-003 |
| 31 | 31 | */ |
| 32 | 32 | |
| 33 | #include <stdio.h> |
| 34 | #include <stdlib.h> |
| 33 | 35 | #include "simplehash.h" |
| 34 | 36 | //#include "timer/timer.h" |
| 35 | 37 | |
| … | … | @@ -47,16 +49,13 @@ static uint write_hash_collisions_count = 0; |
| 47 | 49 | static uint read_hash_collisions_count = 0; |
| 48 | 50 | static uint hash_report_level = 0; |
| 49 | 51 | static uint hash_queries; |
| 50 | | static uint hash_method = 1; |
| 52 | static uint hash_method = QUADRATIC; |
| 51 | 53 | static uint hash_jump_prime = 41; |
| 52 | 54 | static double hash_mult = 3.0; |
| 53 | 55 | static int do_compact_hash = 0; |
| 54 | 56 | |
| 55 | 57 | float mem_opt_factor; |
| 56 | 58 | |
| 57 | | void compact_hash_delete(int *hash){ |
| 58 | | free(hash); |
| 59 | | } |
| 60 | 59 | |
| 61 | 60 | int (*read_hash)(ulong, int *); |
| 62 | 61 | void (*write_hash)(uint, ulong, int *); |
| … | … | @@ -78,7 +77,6 @@ long long get_hashtablesize(void) { |
| 78 | 77 | } |
| 79 | 78 | |
| 80 | 79 | int *compact_hash_init(int ncells, uint isize, uint jsize, uint report_level){ |
| 81 | | |
| 82 | 80 | hash_ncells = 0; |
| 83 | 81 | write_hash_collisions = 0; |
| 84 | 82 | read_hash_collisions = 0; |
| … | … | @@ -126,7 +124,7 @@ int *compact_hash_init(int ncells, uint isize, uint jsize, uint report_level){ |
| 126 | 124 | if (! do_compact_hash) { |
| 127 | 125 | read_hash = read_hash_perfect; |
| 128 | 126 | write_hash = write_hash_perfect; |
| 129 | | } else if (hash_method == 0){ |
| 127 | } else if (hash_method == LINEAR){ |
| 130 | 128 | if (hash_report_level == 0){ |
| 131 | 129 | read_hash = read_hash_linear; |
| 132 | 130 | write_hash = write_hash_linear; |
| … | … | @@ -140,7 +138,7 @@ int *compact_hash_init(int ncells, uint isize, uint jsize, uint report_level){ |
| 140 | 138 | read_hash = read_hash_linear_report_level_3; |
| 141 | 139 | write_hash = write_hash_linear_report_level_3; |
| 142 | 140 | } |
| 143 | | } else if (hash_method == 1){ |
| 141 | } else if (hash_method == QUADRATIC){ |
| 144 | 142 | if (hash_report_level == 0){ |
| 145 | 143 | read_hash = read_hash_quadratic; |
| 146 | 144 | write_hash = write_hash_quadratic; |
| … | … | @@ -154,7 +152,7 @@ int *compact_hash_init(int ncells, uint isize, uint jsize, uint report_level){ |
| 154 | 152 | read_hash = read_hash_quadratic_report_level_3; |
| 155 | 153 | write_hash = write_hash_quadratic_report_level_3; |
| 156 | 154 | } |
| 157 | | } else if (hash_method == 2){ |
| 155 | } else if (hash_method == PRIME_JUMP){ |
| 158 | 156 | if (hash_report_level == 0){ |
| 159 | 157 | read_hash = read_hash_primejump; |
| 160 | 158 | write_hash = write_hash_primejump; |
| … | … | @@ -187,7 +185,6 @@ void write_hash_linear(uint ic, ulong hashkey, int *hash){ |
| 187 | 185 | } |
| 188 | 186 | |
| 189 | 187 | void write_hash_linear_report_level_1(uint ic, ulong hashkey, int *hash){ |
| 190 | | int icount = 0; |
| 191 | 188 | uint hashloc; |
| 192 | 189 | |
| 193 | 190 | hash_ncells++; |
| … | … | @@ -200,7 +197,6 @@ void write_hash_linear_report_level_1(uint ic, ulong hashkey, int *hash){ |
| 200 | 197 | } |
| 201 | 198 | |
| 202 | 199 | void write_hash_linear_report_level_2(uint ic, ulong hashkey, int *hash){ |
| 203 | | int icount = 0; |
| 204 | 200 | uint hashloc; |
| 205 | 201 | |
| 206 | 202 | hash_ncells++; |
| … | … | @@ -1109,16 +1105,19 @@ int read_hash_primejump_report_level_3(ulong hashkey, int *hash){ |
| 1109 | 1105 | return(hashval); |
| 1110 | 1106 | } |
| 1111 | 1107 | |
| 1108 | void compact_hash_delete(int *hash){ |
| 1109 | free(hash); |
| 1110 | } |
| 1112 | 1111 | int read_dev_hash(int hash_method, ulong hashtablesize, ulong AA, ulong BB, ulong hashkey, int *hash){ |
| 1113 | 1112 | //int hash_report_level = 3; |
| 1114 | 1113 | int max_collisions_allowed = 1000; |
| 1115 | 1114 | int hashval = -1; |
| 1116 | 1115 | uint hashloc; |
| 1117 | 1116 | int icount=0; |
| 1118 | | if (hash_method == -1) { |
| 1117 | if (hash_method == PERFECT_HASH) { |
| 1119 | 1118 | return(hash[hashkey]); |
| 1120 | 1119 | } |
| 1121 | | if (hash_method == 0) { |
| 1120 | if (hash_method == LINEAR) { |
| 1122 | 1121 | if (hash_report_level == 0) { |
| 1123 | 1122 | for (hashloc = (hashkey*AA+BB)%prime%hashtablesize; hash[2*hashloc] != (int)hashkey && hash[2*hashloc] != -1; hashloc++,hashloc = hashloc%hashtablesize){ |
| 1124 | 1123 | icount++; |
| … | … | @@ -1155,7 +1154,7 @@ int read_dev_hash(int hash_method, ulong hashtablesize, ulong AA, ulong BB, ulon |
| 1155 | 1154 | } |
| 1156 | 1155 | read_hash_collisions += icount; |
| 1157 | 1156 | } |
| 1158 | | } else if (hash_method == 1) { |
| 1157 | } else if (hash_method == QUADRATIC) { |
| 1159 | 1158 | if (hash_report_level == 0) { |
| 1160 | 1159 | for (hashloc = (hashkey*AA+BB)%prime%hashtablesize; hash[2*hashloc] != (int)hashkey && hash[2*hashloc] != -1; hashloc+=(icount*icount),hashloc = hashloc%hashtablesize){ |
| 1161 | 1160 | icount++; |
| … | … | @@ -1192,7 +1191,7 @@ int read_dev_hash(int hash_method, ulong hashtablesize, ulong AA, ulong BB, ulon |
| 1192 | 1191 | } |
| 1193 | 1192 | read_hash_collisions += icount; |
| 1194 | 1193 | } |
| 1195 | | } else if (hash_method == 2) { |
| 1194 | } else if (hash_method == PRIME_JUMP) { |
| 1196 | 1195 | uint jump = 1+hashkey%hash_jump_prime; |
| 1197 | 1196 | if (hash_report_level == 0) { |
| 1198 | 1197 | for (hashloc = (hashkey*AA+BB)%prime%hashtablesize; hash[2*hashloc] != (int)hashkey && hash[2*hashloc] != -1; hashloc+=(icount*jump),hashloc = hashloc%hashtablesize){ |