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

Function compute_call_depth

src/ui/layout3d.c:408–456  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

406/* ── Call depth via BFS ───────────────────────────────────────── */
407
408static void compute_call_depth(int n, const int *es, const int *ed, int ne, const char **labels,
409 int *depth) {
410 for (int i = 0; i < n; i++)
411 depth[i] = -1;
412 int *q = malloc((size_t)n * sizeof(int));
413 int head = 0, tail = 0;
414 if (!q)
415 return;
416
417 /* Entry points at depth 0 */
418 for (int i = 0; i < n; i++) {
419 if (labels[i] && (strcmp(labels[i], "Route") == 0 || strcmp(labels[i], "File") == 0 ||
420 strcmp(labels[i], "Module") == 0 || strcmp(labels[i], "Package") == 0)) {
421 depth[i] = 0;
422 q[tail++] = i;
423 }
424 }
425 if (tail == 0) {
426 int *in_d = calloc((size_t)n, sizeof(int));
427 if (in_d) {
428 for (int e = 0; e < ne; e++) {
429 int t = ed[e];
430 if (t >= 0 && t < n)
431 in_d[t]++;
432 }
433 for (int i = 0; i < n; i++)
434 if (in_d[i] == 0) {
435 depth[i] = 0;
436 q[tail++] = i;
437 }
438 free(in_d);
439 }
440 }
441 while (head < tail) {
442 int c = q[head++], cd = depth[c];
443 for (int e = 0; e < ne; e++)
444 if (es[e] == c) {
445 int t = ed[e];
446 if (t >= 0 && t < n && depth[t] == -1) {
447 depth[t] = cd + SKIP_ONE;
448 q[tail++] = t;
449 }
450 }
451 }
452 for (int i = 0; i < n; i++)
453 if (depth[i] == -1)
454 depth[i] = 0;
455 free(q);
456}
457
458/* ── Helpers ──────────────────────────────────────────────────── */
459

Callers 1

cbm_layout_from_nodesFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected