Append a candidate to the result buffer, growing if needed. */
| 435 | |
| 436 | /* Append a candidate to the result buffer, growing if needed. */ |
| 437 | static bool result_push(cbm_lsh_index_t *idx, const cbm_lsh_entry_t *candidate) { |
| 438 | if (idx->result_count >= idx->result_cap) { |
| 439 | int new_cap = |
| 440 | idx->result_cap < RESULT_INIT_CAP ? RESULT_INIT_CAP : idx->result_cap * GROW_FACTOR; |
| 441 | const cbm_lsh_entry_t **new_buf = |
| 442 | realloc(idx->result_buf, (size_t)new_cap * sizeof(const cbm_lsh_entry_t *)); |
| 443 | if (!new_buf) { |
| 444 | return false; |
| 445 | } |
| 446 | idx->result_buf = new_buf; |
| 447 | idx->result_cap = new_cap; |
| 448 | } |
| 449 | idx->result_buf[idx->result_count++] = candidate; |
| 450 | return true; |
| 451 | } |
| 452 | |
| 453 | void cbm_lsh_query(const cbm_lsh_index_t *idx, const cbm_minhash_t *fp, |
| 454 | const cbm_lsh_entry_t ***out, int *count) { |