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

Function ref_groups_match

tests/test_cypher.c:5763–5801  ·  view source on GitHub ↗

`got` (column 0 = callee, column 1 = count) must list the callees of * `pairs` (column 0 = callee, column 1 = caller name) in first-seen order, * each with its caller count — of distinct names when `distinct`. */

Source from the content-addressed store, hash-verified

5761 * `pairs` (column 0 = callee, column 1 = caller name) in first-seen order,
5762 * each with its caller count — of distinct names when `distinct`. */
5763static bool ref_groups_match(const cbm_cypher_result_t *got, const cbm_cypher_result_t *pairs,
5764 bool distinct) {
5765 enum { REF_PAIRS_MAX = REF_NODES * 4 };
5766 if (pairs->row_count > REF_PAIRS_MAX) {
5767 return false;
5768 }
5769 bool first_callee[REF_PAIRS_MAX];
5770 bool first_pair[REF_PAIRS_MAX];
5771 for (int k = 0; k < pairs->row_count; k++) {
5772 first_callee[k] = true;
5773 first_pair[k] = true;
5774 for (int m = 0; m < k; m++) {
5775 if (strcmp(pairs->rows[m][0], pairs->rows[k][0]) == 0) {
5776 first_callee[k] = false;
5777 first_pair[k] = first_pair[k] && strcmp(pairs->rows[m][1], pairs->rows[k][1]) != 0;
5778 }
5779 }
5780 }
5781 int groups = 0;
5782 for (int i = 0; i < pairs->row_count; i++) {
5783 if (!first_callee[i]) {
5784 continue;
5785 }
5786 int count = 0;
5787 for (int k = 0; k < pairs->row_count; k++) {
5788 if (strcmp(pairs->rows[k][0], pairs->rows[i][0]) == 0) {
5789 count += !distinct || first_pair[k] ? 1 : 0;
5790 }
5791 }
5792 char want[16];
5793 snprintf(want, sizeof(want), "%d", count);
5794 if (groups >= got->row_count || strcmp(got->rows[groups][0], pairs->rows[i][0]) != 0 ||
5795 strcmp(got->rows[groups][1], want) != 0) {
5796 return false;
5797 }
5798 groups++;
5799 }
5800 return groups == got->row_count;
5801}
5802
5803TEST(cypher_grouping_keeps_first_seen_groups) {
5804 cbm_store_t *s = setup_reference_store();

Callers 1

test_cypher.cFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected