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

Function build_dump_edges

src/graph_buffer/graph_buffer.c:1463–1517  ·  view source on GitHub ↗

Build dump-ready edge array with remapped IDs. Returns url_paths and * local_names (heap string arrays owned by the caller) via out params. */

Source from the content-addressed store, hash-verified

1461/* Build dump-ready edge array with remapped IDs. Returns url_paths and
1462 * local_names (heap string arrays owned by the caller) via out params. */
1463static CBMDumpEdge *build_dump_edges(cbm_gbuf_t *gb, const int64_t *temp_to_final,
1464 int64_t max_temp_id, int *out_count, char ***out_url_paths,
1465 char ***out_local_names) {
1466 /* Count valid edges (both endpoints resolved) */
1467 int valid_edges = 0;
1468 for (int i = 0; i < gb->edges.count; i++) {
1469 cbm_gbuf_edge_t *e = gb->edges.items[i];
1470 if (remap_id(temp_to_final, max_temp_id, e->source_id) > 0 &&
1471 remap_id(temp_to_final, max_temp_id, e->target_id) > 0) {
1472 valid_edges++;
1473 }
1474 }
1475
1476 CBMDumpEdge *dump_edges =
1477 malloc((size_t)(valid_edges > 0 ? valid_edges : SKIP_ONE) * sizeof(CBMDumpEdge));
1478 char **url_paths = calloc((size_t)(valid_edges > 0 ? valid_edges : SKIP_ONE), sizeof(char *));
1479 char **local_names = calloc((size_t)(valid_edges > 0 ? valid_edges : SKIP_ONE), sizeof(char *));
1480 int idx = 0;
1481
1482 for (int i = 0; i < gb->edges.count; i++) {
1483 cbm_gbuf_edge_t *e = gb->edges.items[i];
1484 int64_t src = remap_id(temp_to_final, max_temp_id, e->source_id);
1485 int64_t tgt = remap_id(temp_to_final, max_temp_id, e->target_id);
1486 if (src == 0 || tgt == 0) {
1487 continue;
1488 }
1489
1490 char *url_path = extract_url_path(e->properties_json);
1491 url_paths[idx] = url_path;
1492
1493 /* IMPORTS only — mirrors the local_name_gen CASE in the edges DDL. */
1494 char *local_name = (e->type && strcmp(e->type, "IMPORTS") == 0)
1495 ? extract_local_name(e->properties_json)
1496 : NULL;
1497 local_names[idx] = local_name;
1498
1499 const char *props = e->properties_json ? e->properties_json : "{}";
1500 dump_edges[idx] = (CBMDumpEdge){
1501 .id = idx + SKIP_ONE,
1502 .project = gb->project,
1503 .source_id = src,
1504 .target_id = tgt,
1505 .type = e->type,
1506 .properties = props,
1507 .url_path = url_path ? url_path : "",
1508 .local_name = local_name ? local_name : "",
1509 };
1510 idx++;
1511 }
1512
1513 *out_count = idx;
1514 *out_url_paths = url_paths;
1515 *out_local_names = local_names;
1516 return dump_edges;
1517}
1518
1519/* Remap vector node IDs through temp_to_final, sort by ID, deduplicate. */
1520static void remap_sort_dedup_vectors(cbm_gbuf_t *gb, const int64_t *temp_to_final,

Callers 1

cbm_gbuf_dump_to_sqliteFunction · 0.85

Calls 3

remap_idFunction · 0.85
extract_url_pathFunction · 0.85
extract_local_nameFunction · 0.85

Tested by

no test coverage detected