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

Function cbm_lsh_query

src/simhash/minhash.c:453–490  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

451}
452
453void cbm_lsh_query(const cbm_lsh_index_t *idx, const cbm_minhash_t *fp,
454 const cbm_lsh_entry_t ***out, int *count) {
455 *out = NULL;
456 *count = 0;
457
458 if (!idx || !fp) {
459 return;
460 }
461
462 cbm_lsh_index_t *mut_idx = (cbm_lsh_index_t *)idx;
463 mut_idx->result_count = 0;
464
465 /* O(1) dedup via open-addressing hash set */
466 seen_set_t seen;
467 seen_set_init(&seen);
468
469 for (int b = 0; b < CBM_LSH_BANDS; b++) {
470 uint32_t h = band_hash(fp, b);
471 const lsh_bucket_t *bucket = &idx->bands[b][h];
472 /* Skip oversized buckets — noise from trivially similar utility functions */
473 if (bucket->count > MAX_BUCKET_SIZE) {
474 continue;
475 }
476 for (int i = 0; i < bucket->count; i++) {
477 const cbm_lsh_entry_t *candidate = &idx->entries[bucket->items[i]];
478 if (!seen_set_insert(&seen, candidate->node_id)) {
479 continue; /* already seen */
480 }
481 if (!result_push(mut_idx, candidate)) {
482 break;
483 }
484 }
485 }
486
487 seen_set_free(&seen);
488 *out = mut_idx->result_buf;
489 *count = mut_idx->result_count;
490}
491
492int cbm_lsh_query_into(const cbm_lsh_index_t *idx, const cbm_minhash_t *fp,
493 const cbm_lsh_entry_t **out_buf, int out_cap) {

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