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

Function cross_join_nodes

src/cypher/cypher.c:4551–4582  ·  view source on GitHub ↗

Cross-join node-only pattern into existing bindings. Returns 0 on success, * CBM_NOT_FOUND when the allocation is refused (overflow) or fails (OOM); the * caller propagates that as a query error rather than silently skipping the * MATCH, which would return a wrong (short) result. */

Source from the content-addressed store, hash-verified

4549 * caller propagates that as a query error rather than silently skipping the
4550 * MATCH, which would return a wrong (short) result. */
4551static int cross_join_nodes(binding_t **bindings, int *bind_count, cbm_node_t *extra_nodes,
4552 int extra_count, const char *nvar, bool opt) {
4553 size_t alloc_n = 0;
4554 if (cbm_cypher_cross_join_alloc(*bind_count, extra_count, opt, &alloc_n) != 0) {
4555 return CBM_NOT_FOUND; /* product overflows int/size_t: fail the query */
4556 }
4557 binding_t *new_bindings = malloc(alloc_n * sizeof(binding_t));
4558 if (!new_bindings) {
4559 return CBM_NOT_FOUND; /* OOM: propagate, don't silently skip the MATCH */
4560 }
4561 size_t new_count = 0;
4562 for (int bi = 0; bi < *bind_count; bi++) {
4563 for (int ni = 0; ni < extra_count && new_count < alloc_n; ni++) {
4564 binding_t nb = {0};
4565 binding_copy(&nb, &(*bindings)[bi]);
4566 binding_set(&nb, nvar, &extra_nodes[ni]);
4567 new_bindings[new_count++] = nb;
4568 }
4569 if (opt && extra_count == 0 && new_count < alloc_n) {
4570 binding_t nb = {0};
4571 binding_copy(&nb, &(*bindings)[bi]);
4572 new_bindings[new_count++] = nb;
4573 }
4574 }
4575 for (int bi = 0; bi < *bind_count; bi++) {
4576 binding_free(&(*bindings)[bi]);
4577 }
4578 free(*bindings);
4579 *bindings = new_bindings;
4580 *bind_count = (int)new_count; /* new_count <= INT_MAX, guaranteed above */
4581 return 0;
4582}
4583
4584/* Cross-join pattern-with-rels into existing bindings */
4585static void cross_join_with_rels(cbm_store_t *store, cbm_pattern_t *patn, binding_t **bindings,

Callers 1

Calls 4

binding_copyFunction · 0.85
binding_setFunction · 0.85
binding_freeFunction · 0.85

Tested by

no test coverage detected