Build dump-ready edge array with remapped IDs. Returns url_paths and * local_names (heap string arrays owned by the caller) via out params. */
| 2330 | /* Build dump-ready edge array with remapped IDs. Returns url_paths and |
| 2331 | * local_names (heap string arrays owned by the caller) via out params. */ |
| 2332 | static CBMDumpEdge *build_dump_edges(cbm_gbuf_t *gb, const int64_t *temp_to_final, |
| 2333 | int64_t max_temp_id, int *out_count, char ***out_url_paths, |
| 2334 | char ***out_local_names) { |
| 2335 | /* Count valid edges (both endpoints resolved) */ |
| 2336 | int valid_edges = 0; |
| 2337 | for (int i = 0; i < gb->edges.count; i++) { |
| 2338 | cbm_gbuf_edge_t *e = gb->edges.items[i]; |
| 2339 | if (remap_id(temp_to_final, max_temp_id, e->source_id) > 0 && |
| 2340 | remap_id(temp_to_final, max_temp_id, e->target_id) > 0) { |
| 2341 | valid_edges++; |
| 2342 | } |
| 2343 | } |
| 2344 | |
| 2345 | size_t edge_cap = (size_t)(valid_edges > 0 ? valid_edges : SKIP_ONE); |
| 2346 | CBMDumpEdge *dump_edges = cbm_alloc(CBM_MEM_CLASS_DUMP, edge_cap * sizeof(CBMDumpEdge)); |
| 2347 | char **url_paths = cbm_calloc(CBM_MEM_CLASS_DUMP, edge_cap * sizeof(char *)); |
| 2348 | char **local_names = cbm_calloc(CBM_MEM_CLASS_DUMP, edge_cap * sizeof(char *)); |
| 2349 | int idx = 0; |
| 2350 | |
| 2351 | for (int i = 0; i < gb->edges.count; i++) { |
| 2352 | cbm_gbuf_edge_t *e = gb->edges.items[i]; |
| 2353 | int64_t src = remap_id(temp_to_final, max_temp_id, e->source_id); |
| 2354 | int64_t tgt = remap_id(temp_to_final, max_temp_id, e->target_id); |
| 2355 | if (src == 0 || tgt == 0) { |
| 2356 | continue; |
| 2357 | } |
| 2358 | |
| 2359 | char *url_path = extract_url_path(e->properties_json); |
| 2360 | url_paths[idx] = url_path; |
| 2361 | |
| 2362 | /* IMPORTS only — mirrors the local_name_gen CASE in the edges DDL. */ |
| 2363 | char *local_name = (e->type && strcmp(e->type, "IMPORTS") == 0) |
| 2364 | ? extract_local_name(e->properties_json) |
| 2365 | : NULL; |
| 2366 | local_names[idx] = local_name; |
| 2367 | |
| 2368 | const char *props = e->properties_json ? e->properties_json : "{}"; |
| 2369 | dump_edges[idx] = (CBMDumpEdge){ |
| 2370 | .id = idx + SKIP_ONE, |
| 2371 | .project = gb->project, |
| 2372 | .source_id = src, |
| 2373 | .target_id = tgt, |
| 2374 | .type = e->type, |
| 2375 | .properties = props, |
| 2376 | .url_path = url_path ? url_path : "", |
| 2377 | .local_name = local_name ? local_name : "", |
| 2378 | }; |
| 2379 | idx++; |
| 2380 | } |
| 2381 | |
| 2382 | *out_count = idx; |
| 2383 | *out_url_paths = url_paths; |
| 2384 | *out_local_names = local_names; |
| 2385 | return dump_edges; |
| 2386 | } |
| 2387 | |
| 2388 | /* Remap vector node IDs through temp_to_final, sort by ID, deduplicate. */ |
| 2389 | static void remap_sort_dedup_vectors(cbm_gbuf_t *gb, const int64_t *temp_to_final, |
no test coverage detected