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

Function process_edges

src/cypher/cypher.c:3497–3543  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3495}
3496
3497static void process_edges(cbm_store_t *store, cbm_edge_t *edges, int edge_count, bool inbound,
3498 const cbm_node_pattern_t *target_node, binding_t *b, const char *to_var,
3499 const char *rel_var, binding_t **new_bindings, int *new_count,
3500 int *new_cap, int *match_count) {
3501 /* When the terminal node variable is ALREADY bound (e.g. the second pattern
3502 * `(c)-[:CALLS]->(f)` where `f` came from an earlier MATCH), we must FILTER
3503 * to edges that actually reach the bound node — not overwrite the caller's
3504 * `f` binding with whatever node the edge leads to. Overwriting corrupted
3505 * the result of dead-code queries and produced wrong rows (#627). */
3506 cbm_node_t *bound_to = binding_get(b, to_var);
3507 int64_t bound_to_id = bound_to ? bound_to->id : 0;
3508 /* The budget caps MATERIALISATION, not detection: `match_count` must stay
3509 * truthful even after `new_count` hits `max_new`. Gating the loop itself
3510 * (`ei < edge_count && *new_count < max_new`) stopped fetching entirely, so
3511 * a saturated source reported `match_count == 0` despite having neighbours —
3512 * and the OPTIONAL fallback in expand_pattern_rels then emitted an unbound
3513 * "no match" row for it. `WHERE x IS NULL` reads those rows as "nothing
3514 * points here", i.e. it reported live code as dead. Losing rows is
3515 * recoverable; asserting a match does not exist when it does is not. */
3516 for (int ei = 0; ei < edge_count; ei++) {
3517 int64_t tid = inbound ? edges[ei].source_id : edges[ei].target_id;
3518 if (bound_to && tid != bound_to_id) {
3519 continue; /* edge does not reach the already-bound terminal node */
3520 }
3521 cbm_node_t found = {0};
3522 if (cbm_store_find_node_by_id(store, tid, &found) != CBM_STORE_OK) {
3523 continue;
3524 }
3525 if (target_node->label && !label_alt_matches(found.label, target_node->label)) {
3526 node_fields_free(&found);
3527 continue;
3528 }
3529 if (!check_inline_props(&found, target_node->props, target_node->prop_count, store)) {
3530 node_fields_free(&found);
3531 continue;
3532 }
3533 (*match_count)++; /* a real neighbour exists, OOM or not */
3534 binding_t nb = {0};
3535 binding_copy(&nb, b);
3536 binding_take_node(&nb, to_var, &found);
3537 if (rel_var) {
3538 binding_set_edge(&nb, rel_var, &edges[ei]);
3539 }
3540 (void)binding_out_append(new_bindings, new_count, new_cap, &nb);
3541 node_fields_free(&found);
3542 }
3543}
3544
3545/* Expand variable-length relationship via BFS */
3546/* Set when a variable-length hop range is clamped to the engine ceiling

Callers 1

expand_fixed_lengthFunction · 0.85

Calls 9

binding_getFunction · 0.85
label_alt_matchesFunction · 0.85
node_fields_freeFunction · 0.85
check_inline_propsFunction · 0.85
binding_copyFunction · 0.85
binding_take_nodeFunction · 0.85
binding_set_edgeFunction · 0.85
binding_out_appendFunction · 0.85

Tested by

no test coverage detected