| 392 | } |
| 393 | |
| 394 | void cbm_lsh_insert(cbm_lsh_index_t *idx, const cbm_lsh_entry_t *entry) { |
| 395 | if (!idx || !entry || !entry->fingerprint) { |
| 396 | return; |
| 397 | } |
| 398 | |
| 399 | /* Store a copy of the entry */ |
| 400 | if (idx->entry_count >= idx->entry_cap) { |
| 401 | int new_cap = |
| 402 | idx->entry_cap < ENTRY_INIT_CAP ? ENTRY_INIT_CAP : idx->entry_cap * GROW_FACTOR; |
| 403 | cbm_lsh_entry_t *new_entries = cbm_realloc(CBM_MEM_CLASS_SEMANTIC, idx->entries, |
| 404 | (size_t)new_cap * sizeof(cbm_lsh_entry_t)); |
| 405 | if (!new_entries) { |
| 406 | return; |
| 407 | } |
| 408 | idx->entries = new_entries; |
| 409 | idx->entry_cap = new_cap; |
| 410 | } |
| 411 | int entry_idx = idx->entry_count; |
| 412 | idx->entries[entry_idx] = *entry; |
| 413 | idx->entry_count++; |
| 414 | |
| 415 | /* Insert index into each band's bucket */ |
| 416 | for (int b = 0; b < CBM_LSH_BANDS; b++) { |
| 417 | uint32_t h = band_hash(entry->fingerprint, b); |
| 418 | bucket_push(&idx->bands[b][h], entry_idx); |
| 419 | } |
| 420 | } |
| 421 | |
| 422 | /* O(1) seen-set: open-addressing hash table on node_id for dedup. */ |
| 423 | typedef struct { |
no test coverage detected