| 675 | } |
| 676 | |
| 677 | static void batch_resolve_worker(int worker_id, void *ctx_ptr) { |
| 678 | (void)worker_id; |
| 679 | batch_resolve_ctx_t *bc = ctx_ptr; |
| 680 | /* Per-worker scratch for unique-per-doc tracking */ |
| 681 | int local_seen_cap = CBM_SEM_SEEN_INIT_CAP; |
| 682 | int *seen = cbm_alloc(CBM_MEM_CLASS_SEMANTIC, (size_t)local_seen_cap * sizeof(int)); |
| 683 | if (!seen) { |
| 684 | return; |
| 685 | } |
| 686 | |
| 687 | while (true) { |
| 688 | int start = |
| 689 | atomic_fetch_add_explicit(&bc->next_idx, CBM_SEM_RESOLVE_CHUNK, memory_order_relaxed); |
| 690 | if (start >= bc->doc_count) { |
| 691 | break; |
| 692 | } |
| 693 | int end = start + CBM_SEM_RESOLVE_CHUNK; |
| 694 | if (end > bc->doc_count) { |
| 695 | end = bc->doc_count; |
| 696 | } |
| 697 | for (int d = start; d < end; d++) { |
| 698 | int count = bc->token_counts[d]; |
| 699 | if (count > local_seen_cap) { |
| 700 | int *grown = cbm_realloc(CBM_MEM_CLASS_SEMANTIC, seen, (size_t)count * sizeof(int)); |
| 701 | if (!grown) { |
| 702 | continue; |
| 703 | } |
| 704 | seen = grown; |
| 705 | local_seen_cap = count; |
| 706 | } |
| 707 | batch_resolve_one_doc(bc, d, seen); |
| 708 | } |
| 709 | } |
| 710 | cbm_free(CBM_MEM_CLASS_SEMANTIC, seen); |
| 711 | } |
| 712 | |
| 713 | void cbm_sem_corpus_add_docs_batch(cbm_sem_corpus_t *corpus, char **all_tokens, |
| 714 | const size_t *offsets, const int *token_counts, int doc_count) { |
nothing calls this directly
no test coverage detected