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

Function cbm_lsh_query

src/simhash/minhash.c:475–512  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

473}
474
475void cbm_lsh_query(const cbm_lsh_index_t *idx, const cbm_minhash_t *fp,
476 const cbm_lsh_entry_t ***out, int *count) {
477 *out = NULL;
478 *count = 0;
479
480 if (!idx || !fp) {
481 return;
482 }
483
484 cbm_lsh_index_t *mut_idx = (cbm_lsh_index_t *)idx;
485 mut_idx->result_count = 0;
486
487 /* O(1) dedup via open-addressing hash set */
488 seen_set_t seen;
489 seen_set_init(&seen);
490
491 for (int b = 0; b < CBM_LSH_BANDS; b++) {
492 uint32_t h = band_hash(fp, b);
493 const lsh_bucket_t *bucket = &idx->bands[b][h];
494 /* Skip oversized buckets — noise from trivially similar utility functions */
495 if (bucket->count > MAX_BUCKET_SIZE) {
496 continue;
497 }
498 for (int i = 0; i < bucket->count; i++) {
499 const cbm_lsh_entry_t *candidate = &idx->entries[bucket->items[i]];
500 if (!seen_set_insert(&seen, candidate->node_id)) {
501 continue; /* already seen */
502 }
503 if (!result_push(mut_idx, candidate)) {
504 break;
505 }
506 }
507 }
508
509 seen_set_free(&seen);
510 *out = mut_idx->result_buf;
511 *count = mut_idx->result_count;
512}
513
514/* The reusable set: a slot belongs to the running query only when its stamp is
515 * the current generation. Same size, hash and probe order as seen_set_t, so the

Callers 1

test_simhash.cFile · 0.85

Calls 5

seen_set_initFunction · 0.85
band_hashFunction · 0.85
seen_set_insertFunction · 0.85
result_pushFunction · 0.85
seen_set_freeFunction · 0.85

Tested by

no test coverage detected