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

Function sort_bindings

src/cypher/cypher.c:3750–3774  ·  view source on GitHub ↗

Sort bindings by the ORDER BY key list (virtual variables) using bubble * sort; later keys break ties, direction is per key (#1334). */

Source from the content-addressed store, hash-verified

3748/* Sort bindings by the ORDER BY key list (virtual variables) using bubble
3749 * sort; later keys break ties, direction is per key (#1334). */
3750static void sort_bindings(binding_t *vbindings, int count, const cbm_return_clause_t *wc) {
3751 for (int i = 0; i < count - SKIP_ONE; i++) {
3752 for (int j = 0; j < count - i - SKIP_ONE; j++) {
3753 int cmp = 0;
3754 for (int k = 0; k < wc->order_key_count && cmp == 0; k++) {
3755 const char *va = binding_get_virtual(&vbindings[j], wc->order_keys[k], NULL);
3756 const char *vb2 =
3757 binding_get_virtual(&vbindings[j + SKIP_ONE], wc->order_keys[k], NULL);
3758 char *ea = NULL;
3759 char *eb = NULL;
3760 double da = strtod(va, &ea);
3761 double db = strtod(vb2, &eb);
3762 cmp = (ea != va && eb != vb2) ? ((da > db) - (da < db)) : strcmp(va, vb2);
3763 if (wc->order_descs[k]) {
3764 cmp = -cmp;
3765 }
3766 }
3767 if (cmp > 0) {
3768 binding_t tmp = vbindings[j];
3769 vbindings[j] = vbindings[j + SKIP_ONE];
3770 vbindings[j + SKIP_ONE] = tmp;
3771 }
3772 }
3773 }
3774}
3775
3776/* Apply skip and limit to a binding array, freeing discarded entries */
3777static void bindings_skip_limit(binding_t *vbindings, int *count, int skip, int limit) {

Callers 1

with_sort_skip_limitFunction · 0.85

Calls 1

binding_get_virtualFunction · 0.85

Tested by

no test coverage detected