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

Function batch_resolve_one_doc

src/semantic/semantic.c:634–675  ·  view source on GitHub ↗

Resolve one document: look up each token's global ID, fill the corpus * doc_token_ids[d], and bump the per-token doc_freq counter atomically. The * caller is responsible for ensuring `seen` has capacity for `count` ints * before calling (the worker grows its per-thread scratch buffer). */

Source from the content-addressed store, hash-verified

632 * caller is responsible for ensuring `seen` has capacity for `count` ints
633 * before calling (the worker grows its per-thread scratch buffer). */
634static void batch_resolve_one_doc(batch_resolve_ctx_t *bc, int doc_index, int *seen) {
635 int count = bc->token_counts[doc_index];
636 if (count <= 0) {
637 bc->corpus->doc_token_ids[doc_index] = NULL;
638 bc->corpus->doc_token_counts[doc_index] = 0;
639 return;
640 }
641 int *ids = cbm_alloc(CBM_MEM_CLASS_SEMANTIC, (size_t)count * sizeof(int));
642 bc->corpus->doc_token_ids[doc_index] = ids;
643 bc->corpus->doc_token_counts[doc_index] = count;
644
645 int seen_count = 0;
646 char **tokens = &bc->all_tokens[bc->offsets[doc_index]];
647 for (int i = 0; i < count; i++) {
648 const char *idx_str = cbm_ht_get(bc->corpus->token_map, tokens[i]);
649 int tid = CBM_NOT_FOUND;
650 if (idx_str) {
651 char *end = NULL;
652 long parsed = strtol(idx_str, &end, BASE_DECIMAL);
653 if (end != idx_str) {
654 tid = (int)parsed;
655 }
656 }
657 ids[i] = tid;
658 if (tid < 0) {
659 continue;
660 }
661 /* Unique-per-doc check for IDF */
662 bool is_new = true;
663 for (int j = 0; j < seen_count; j++) {
664 if (seen[j] == tid) {
665 is_new = false;
666 break;
667 }
668 }
669 if (is_new) {
670 seen[seen_count++] = tid;
671 atomic_fetch_add_explicit(&bc->doc_freq_atomic[tid], CBM_SEM_ATOMIC_INC,
672 memory_order_relaxed);
673 }
674 }
675}
676
677static void batch_resolve_worker(int worker_id, void *ctx_ptr) {
678 (void)worker_id;

Callers 1

batch_resolve_workerFunction · 0.85

Calls 2

cbm_allocFunction · 0.85
cbm_ht_getFunction · 0.85

Tested by

no test coverage detected