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

Function with_apply_distinct

src/cypher/cypher.c:3733–3757  ·  view source on GitHub ↗

Apply WITH DISTINCT: drop projected rows whose value tuple duplicates an * earlier one, keeping first occurrence (#238 — previously silently ignored). */

Source from the content-addressed store, hash-verified

3731/* Apply WITH DISTINCT: drop projected rows whose value tuple duplicates an
3732 * earlier one, keeping first occurrence (#238 — previously silently ignored). */
3733static void with_apply_distinct(cbm_return_clause_t *wc, binding_t *vbindings, int *vcount) {
3734 int kept = 0;
3735 for (int i = 0; i < *vcount; i++) {
3736 char key[CBM_SZ_1K];
3737 with_proj_key(wc, &vbindings[i], key, sizeof(key));
3738 bool dup = false;
3739 for (int j = 0; j < kept; j++) {
3740 char pkey[CBM_SZ_1K];
3741 with_proj_key(wc, &vbindings[j], pkey, sizeof(pkey));
3742 if (strcmp(key, pkey) == 0) {
3743 dup = true;
3744 break;
3745 }
3746 }
3747 if (dup) {
3748 binding_free(&vbindings[i]);
3749 } else {
3750 if (kept != i) {
3751 vbindings[kept] = vbindings[i];
3752 }
3753 kept++;
3754 }
3755 }
3756 *vcount = kept;
3757}
3758
3759static void execute_with_clause(cbm_query_t *q, binding_t **bindings_ptr, int *bind_count_ptr) {
3760 cbm_return_clause_t *wc = q->with_clause;

Callers 1

execute_with_clauseFunction · 0.85

Calls 2

with_proj_keyFunction · 0.85
binding_freeFunction · 0.85

Tested by

no test coverage detected