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

Function with_apply_distinct

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

4940/* Apply WITH DISTINCT: drop projected rows whose value tuple duplicates an
4941 * earlier one, keeping first occurrence (#238 — previously silently ignored). */
4942static void with_apply_distinct(cbm_return_clause_t *wc, binding_t *vbindings, int *vcount) {
4943 cypher_key_index_t seen = {0};
4944 int kept = 0;
4945 for (int i = 0; i < *vcount; i++) {
4946 char key[CBM_SZ_1K];
4947 with_proj_key(wc, &vbindings[i], key, sizeof(key));
4948 int found = key_index_find(&seen, key);
4949 for (int j = 0; found == KEY_INDEX_UNKNOWN && j < kept; j++) {
4950 char pkey[CBM_SZ_1K];
4951 with_proj_key(wc, &vbindings[j], pkey, sizeof(pkey));
4952 if (strcmp(key, pkey) == 0) {
4953 found = j;
4954 }
4955 }
4956 if (found >= 0) {
4957 binding_free(&vbindings[i]);
4958 } else {
4959 key_index_add(&seen, key, kept);
4960 if (kept != i) {
4961 vbindings[kept] = vbindings[i];
4962 }
4963 kept++;
4964 }
4965 }
4966 *vcount = kept;
4967 key_index_free(&seen);
4968}
4969
4970/* The WITH output once every binding has been fed: projected rows (one per
4971 * group or per binding), de-duplicated, sorted, skipped/limited and filtered

Callers 1

with_sink_finishFunction · 0.85

Calls 5

with_proj_keyFunction · 0.85
key_index_findFunction · 0.85
binding_freeFunction · 0.85
key_index_addFunction · 0.85
key_index_freeFunction · 0.85

Tested by

no test coverage detected