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

Function twin_keys

internal/cbm/doclink.c:440–470  ·  view source on GitHub ↗

The (line, name) keys of the definitions a twin label duplicates, sorted; * NULL when there are none. */

Source from the content-addressed store, hash-verified

438/* The (line, name) keys of the definitions a twin label duplicates, sorted;
439 * NULL when there are none. */
440static doclink_twin_key_t *twin_keys(CBMExtractCtx *ctx, const char *label, int *out_count) {
441 *out_count = 0;
442 const CBMDefArray *defs = &ctx->result->defs;
443 int n = 0;
444 for (int i = 0; i < defs->count; i++) {
445 const CBMDefinition *d = &defs->items[i];
446 if (d->label && d->name && strcmp(d->label, label) == 0) {
447 n++;
448 }
449 }
450 if (n == 0) {
451 return NULL;
452 }
453 doclink_twin_key_t *keys = (doclink_twin_key_t *)cbm_arena_alloc(
454 doclink_scratch(ctx), (size_t)n * sizeof(doclink_twin_key_t));
455 if (!keys) {
456 return NULL;
457 }
458 int k = 0;
459 for (int i = 0; i < defs->count; i++) {
460 const CBMDefinition *d = &defs->items[i];
461 if (d->label && d->name && strcmp(d->label, label) == 0) {
462 keys[k].line = d->start_line;
463 keys[k].name = d->name;
464 k++;
465 }
466 }
467 qsort(keys, (size_t)k, sizeof(keys[0]), twin_key_cmp);
468 *out_count = k;
469 return keys;
470}
471
472/* True when a doc taken from a definition, or the file's own doc, starts on
473 * one of the lines [first, last]. */

Callers 1

cbm_doclinks_extractFunction · 0.85

Calls 2

doclink_scratchFunction · 0.85
cbm_arena_allocFunction · 0.70

Tested by

no test coverage detected