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

Function build_dump_nodes

src/graph_buffer/graph_buffer.c:2284–2328  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2282}
2283
2284static CBMDumpNode *build_dump_nodes(cbm_gbuf_t *gb, int live_count, int64_t *temp_to_final,
2285 int64_t max_temp_id, int *out_count,
2286 cbm_gbuf_node_t ***src_out) {
2287 size_t cap = (size_t)(live_count > 0 ? live_count : SKIP_ONE);
2288 CBMDumpNode *dump_nodes = cbm_alloc(CBM_MEM_CLASS_DUMP, cap * sizeof(CBMDumpNode));
2289 /* Parallel gbuf-node pointers so a streamed partition can free its heavy
2290 * properties_json after the rows are persisted. NULL on OOM disables the
2291 * per-partition free (the dump still succeeds). */
2292 cbm_gbuf_node_t **src = cbm_alloc(CBM_MEM_CLASS_DUMP, cap * sizeof(cbm_gbuf_node_t *));
2293 int idx = 0;
2294
2295 for (int i = 0; i < gb->nodes.count; i++) {
2296 cbm_gbuf_node_t *n = gb->nodes.items[i];
2297 if (!n->qualified_name || !cbm_ht_get(gb->node_by_qn, n->qualified_name)) {
2298 continue;
2299 }
2300
2301 int64_t final_id = idx + SKIP_ONE; /* 1-based sequential */
2302 if (n->id < max_temp_id) {
2303 temp_to_final[n->id] = final_id;
2304 }
2305
2306 const char *fp = n->file_path ? n->file_path : "";
2307 const char *props = n->properties_json ? n->properties_json : "{}";
2308 dump_nodes[idx] = (CBMDumpNode){
2309 .id = final_id,
2310 .project = gb->project,
2311 .label = n->label,
2312 .name = n->name,
2313 .qualified_name = n->qualified_name,
2314 .file_path = fp,
2315 .start_line = n->start_line,
2316 .end_line = n->end_line,
2317 .properties = props,
2318 };
2319 if (src) {
2320 src[idx] = n;
2321 }
2322 idx++;
2323 }
2324
2325 *out_count = idx;
2326 *src_out = src;
2327 return dump_nodes;
2328}
2329
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. */

Callers 1

cbm_gbuf_dump_to_sqliteFunction · 0.85

Calls 2

cbm_allocFunction · 0.85
cbm_ht_getFunction · 0.85

Tested by

no test coverage detected