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

Function with_apply_distinct

src/cypher/cypher.c:4078–4102  ·  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

4076/* Apply WITH DISTINCT: drop projected rows whose value tuple duplicates an
4077 * earlier one, keeping first occurrence (#238 — previously silently ignored). */
4078static void with_apply_distinct(cbm_return_clause_t *wc, binding_t *vbindings, int *vcount) {
4079 int kept = 0;
4080 for (int i = 0; i < *vcount; i++) {
4081 char key[CBM_SZ_1K];
4082 with_proj_key(wc, &vbindings[i], key, sizeof(key));
4083 bool dup = false;
4084 for (int j = 0; j < kept; j++) {
4085 char pkey[CBM_SZ_1K];
4086 with_proj_key(wc, &vbindings[j], pkey, sizeof(pkey));
4087 if (strcmp(key, pkey) == 0) {
4088 dup = true;
4089 break;
4090 }
4091 }
4092 if (dup) {
4093 binding_free(&vbindings[i]);
4094 } else {
4095 if (kept != i) {
4096 vbindings[kept] = vbindings[i];
4097 }
4098 kept++;
4099 }
4100 }
4101 *vcount = kept;
4102}
4103
4104static void execute_with_clause(cbm_query_t *q, binding_t **bindings_ptr, int *bind_count_ptr) {
4105 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