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

Function gb_note_collision

src/graph_buffer/graph_buffer.c:1036–1064  ·  view source on GitHub ↗

A same-QN collision: gather both sides' spans for the surviving node, * whichever label wins and however many there are. Call it before the * winner is decided, while `existing` still holds its own fields. * `arrival_spans` are the arrival's spans gathered in a worker buffer (they * already include its own); NULL when it brings none. */

Source from the content-addressed store, hash-verified

1034 * `arrival_spans` are the arrival's spans gathered in a worker buffer (they
1035 * already include its own); NULL when it brings none. */
1036static void gb_note_collision(cbm_gbuf_t *gb, const cbm_gbuf_node_t *existing,
1037 const gb_def_t *arrival, const gb_span_vec_t *arrival_spans) {
1038 gb_def_t prior = {existing->label, existing->properties_json, existing->file_path,
1039 existing->start_line, existing->end_line};
1040 bool arrival_has = arrival_spans ? arrival_spans->count > 0 : gb_def_has_spans(arrival);
1041 if (!existing->qualified_name || (!gb_def_has_spans(&prior) && !arrival_has)) {
1042 return;
1043 }
1044 if (!gb->variant_spans) {
1045 gb->variant_spans = cbm_ht_create_in(CBM_MEM_CLASS_GBUF_INDEX, 0);
1046 if (!gb->variant_spans) {
1047 return;
1048 }
1049 }
1050 gb_span_vec_t *vec = cbm_ht_get(gb->variant_spans, existing->qualified_name);
1051 if (!vec) {
1052 vec = cbm_calloc(CBM_MEM_CLASS_GBUF_INDEX, sizeof(*vec));
1053 if (!vec) {
1054 return;
1055 }
1056 gb_collect_spans(gb, vec, &prior);
1057 cbm_ht_set(gb->variant_spans, existing->qualified_name, vec);
1058 }
1059 if (arrival_spans) {
1060 gb_append_spans(gb, vec, arrival_spans);
1061 } else {
1062 gb_collect_spans(gb, vec, arrival);
1063 }
1064}
1065
1066/* A worker node copied into this buffer brings the spans it gathered there. */
1067static void gb_adopt_spans(cbm_gbuf_t *gb, const cbm_gbuf_node_t *node, const gb_span_vec_t *from) {

Callers 2

cbm_gbuf_upsert_nodeFunction · 0.85
merge_update_existingFunction · 0.85

Calls 7

gb_def_has_spansFunction · 0.85
cbm_ht_create_inFunction · 0.85
cbm_ht_getFunction · 0.85
cbm_callocFunction · 0.85
gb_collect_spansFunction · 0.85
cbm_ht_setFunction · 0.85
gb_append_spansFunction · 0.85

Tested by

no test coverage detected