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

Function batch_resolve_one_doc

src/semantic/semantic.c:626–667  ·  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

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

Callers 1

batch_resolve_workerFunction · 0.85

Calls 1

cbm_ht_getFunction · 0.85

Tested by

no test coverage detected