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

Function with_apply_distinct

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

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