* Looks for random keys which * ALL can fit in hash table (no errors) */
| 154 | * ALL can fit in hash table (no errors) |
| 155 | */ |
| 156 | static int |
| 157 | get_input_keys(unsigned int with_pushes, unsigned int table_index, |
| 158 | unsigned int ext) |
| 159 | { |
| 160 | unsigned i, j; |
| 161 | unsigned bucket_idx, incr, success = 1; |
| 162 | uint8_t k = 0; |
| 163 | int32_t ret; |
| 164 | const uint32_t bucket_bitmask = NUM_BUCKETS - 1; |
| 165 | unsigned int keys_to_add; |
| 166 | |
| 167 | if (!ext) |
| 168 | keys_to_add = KEYS_TO_ADD * ADD_PERCENT; |
| 169 | else |
| 170 | keys_to_add = KEYS_TO_ADD; |
| 171 | /* Reset all arrays */ |
| 172 | for (i = 0; i < MAX_ENTRIES; i++) |
| 173 | slot_taken[i] = 0; |
| 174 | |
| 175 | for (i = 0; i < NUM_BUCKETS; i++) |
| 176 | buckets[i] = 0; |
| 177 | |
| 178 | for (j = 0; j < hashtest_key_lens[table_index]; j++) |
| 179 | keys[0][j] = 0; |
| 180 | |
| 181 | /* |
| 182 | * Add only entries that are not duplicated and that fits in the table |
| 183 | * (cannot store more than BUCKET_SIZE entries in a bucket). |
| 184 | * Regardless a key has been added correctly or not (success), |
| 185 | * the next one to try will be increased by 1. |
| 186 | */ |
| 187 | for (i = 0; i < keys_to_add;) { |
| 188 | incr = 0; |
| 189 | if (i != 0) { |
| 190 | keys[i][0] = ++k; |
| 191 | /* Overflow, need to increment the next byte */ |
| 192 | if (keys[i][0] == 0) |
| 193 | incr = 1; |
| 194 | for (j = 1; j < hashtest_key_lens[table_index]; j++) { |
| 195 | /* Do not increase next byte */ |
| 196 | if (incr == 0) |
| 197 | if (success == 1) |
| 198 | keys[i][j] = keys[i - 1][j]; |
| 199 | else |
| 200 | keys[i][j] = keys[i][j]; |
| 201 | /* Increase next byte by one */ |
| 202 | else { |
| 203 | if (success == 1) |
| 204 | keys[i][j] = keys[i-1][j] + 1; |
| 205 | else |
| 206 | keys[i][j] = keys[i][j] + 1; |
| 207 | if (keys[i][j] == 0) |
| 208 | incr = 1; |
| 209 | else |
| 210 | incr = 0; |
| 211 | } |
| 212 | } |
| 213 | } |
no test coverage detected