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

Function cbm_gbuf_merge

src/graph_buffer/graph_buffer.c:2187–2232  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2185}
2186
2187int cbm_gbuf_merge(cbm_gbuf_t *dst, cbm_gbuf_t *src) {
2188 if (!dst || !src) {
2189 return CBM_NOT_FOUND;
2190 }
2191 if (src->nodes.count == 0 && src->edges.count == 0) {
2192 return 0;
2193 }
2194
2195 /* ID remap for QN-colliding nodes: "src_id" → (int64_t*) dst_id.
2196 * Only populated when a src node's QN already exists in dst. */
2197 CBMHashTable *remap = NULL;
2198
2199 for (int i = 0; i < src->nodes.count; i++) {
2200 cbm_gbuf_node_t *sn = src->nodes.items[i];
2201 if (!sn->qualified_name) {
2202 continue;
2203 }
2204
2205 /* Skip nodes deleted from QN index */
2206 if (!cbm_ht_get(src->node_by_qn, sn->qualified_name)) {
2207 continue;
2208 }
2209
2210 /* The spans src gathered for this node travel with it; they are
2211 * written once, when dst is exported. */
2212 const gb_span_vec_t *spans =
2213 src->variant_spans ? cbm_ht_get(src->variant_spans, sn->qualified_name) : NULL;
2214 cbm_gbuf_node_t *existing = cbm_ht_get(dst->node_by_qn, sn->qualified_name);
2215 if (existing) {
2216 merge_update_existing(dst, existing, sn, spans, &remap);
2217 } else {
2218 merge_copy_new_node(dst, sn);
2219 gb_adopt_spans(dst, cbm_ht_get(dst->node_by_qn, sn->qualified_name), spans);
2220 }
2221 }
2222
2223 /* Merge edges with optional ID remapping */
2224 merge_remap_edges(dst, src, remap);
2225
2226 if (remap) {
2227 cbm_ht_foreach(remap, free_remap_entry, NULL);
2228 cbm_ht_free(remap);
2229 }
2230
2231 return 0;
2232}
2233
2234/* ── Dump / Flush ────────────────────────────────────────────────── */
2235

Callers 4

cbm_parallel_extract_exFunction · 0.85
cbm_parallel_resolveFunction · 0.85
test_parallel.cFile · 0.85

Calls 7

cbm_ht_getFunction · 0.85
merge_update_existingFunction · 0.85
merge_copy_new_nodeFunction · 0.85
gb_adopt_spansFunction · 0.85
merge_remap_edgesFunction · 0.85
cbm_ht_foreachFunction · 0.85
cbm_ht_freeFunction · 0.85

Tested by

no test coverage detected