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

Function gm_scan_row

src/store/graph_mem.c:294–334  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

292} gm_scan_t;
293
294static bool gm_scan_row(cbm_graph_mem_t *g, gm_scan_t *sc, sqlite3_stmt *st) {
295 int64_t src = sqlite3_column_int64(st, 0);
296 int64_t dst = sqlite3_column_int64(st, GM_COL_TARGET);
297 const unsigned char *type = sqlite3_column_text(st, GM_COL_TYPE);
298 if (src < 0 || dst < 0 || src >= GM_ID_LIMIT || dst >= GM_ID_LIMIT || src < sc->prev_src ||
299 !type || g->n_edges >= (uint32_t)GM_ID_LIMIT) {
300 return false;
301 }
302 int type_id = gm_intern(g, type, (size_t)sqlite3_column_bytes(st, GM_COL_TYPE), &sc->last_type);
303 if (type_id < 0 || !gm_grow_u32(&g->out_off, &sc->off_cap, (size_t)src + GM_GROWTH)) {
304 return false;
305 }
306 while (sc->next_start <= (uint32_t)src) {
307 g->out_off[sc->next_start++] = g->n_edges;
308 }
309 if (g->n_edges >= sc->edge_cap) {
310 size_t next = sc->edge_cap ? sc->edge_cap * GM_GROWTH : 1;
311 uint32_t *nbr = cbm_realloc(CBM_MEM_CLASS_GRAPH_CACHE, g->out_nbr, next * sizeof(uint32_t));
312 if (!nbr) {
313 return false;
314 }
315 g->out_nbr = nbr;
316 uint8_t *types = cbm_realloc(CBM_MEM_CLASS_GRAPH_CACHE, g->out_type, next);
317 if (!types) {
318 return false;
319 }
320 g->out_type = types;
321 sc->edge_cap = next;
322 }
323 g->out_nbr[g->n_edges] = (uint32_t)dst;
324 g->out_type[g->n_edges] = (uint8_t)type_id;
325 g->n_edges++;
326 sc->prev_src = src;
327 if ((uint32_t)src > sc->max_id) {
328 sc->max_id = (uint32_t)src;
329 }
330 if ((uint32_t)dst > sc->max_id) {
331 sc->max_id = (uint32_t)dst;
332 }
333 return true;
334}
335
336/* The in-CSR from the out-CSR: count, prefix-sum, then place each edge using
337 * in_off[v] as v's cursor, which leaves in_off shifted by one id — shift it

Callers 1

gm_buildFunction · 0.85

Calls 3

gm_internFunction · 0.85
gm_grow_u32Function · 0.85
cbm_reallocFunction · 0.85

Tested by

no test coverage detected