MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / cbm_lsh_insert

Function cbm_lsh_insert

src/simhash/minhash.c:394–420  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

392}
393
394void 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. */
423typedef struct {

Callers 2

test_simhash.cFile · 0.85

Calls 3

cbm_reallocFunction · 0.85
band_hashFunction · 0.85
bucket_pushFunction · 0.85

Tested by

no test coverage detected