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

Function build_interior_cell

internal/cbm/sqlite_writer.c:564–577  ·  view source on GitHub ↗

Build interior pages from child page references. Returns the root page number. SQLite interior page structure: - Header has right-child pointer (the last child page) - Each cell contains: child_page(4) + key - For N children, there are N-1 cells (children[0..N-2] get cells, children[N-1] becomes the right-child in the header) - Cell[j] = {left_child: children[j].page, key: children[j].max_key/sep

Source from the content-addressed store, hash-verified

562// cell_buf must be at least 20 bytes for table cells.
563// For index cells, returns malloc'd data via *out_heap (caller frees).
564static int build_interior_cell(const PageRef *child, bool is_index, uint8_t *cell_buf,
565 uint8_t **out_heap) {
566 *out_heap = NULL;
567 if (!is_index) {
568 put_u32(cell_buf, child->page_num);
569 return BTREE_PTR_SIZE + put_varint(cell_buf + BTREE_PTR_SIZE, child->max_key);
570 }
571 int clen = BTREE_PTR_SIZE + child->sep_cell_len;
572 uint8_t *data = (uint8_t *)malloc(clen);
573 put_u32(data, child->page_num);
574 memcpy(data + 4, child->sep_cell, child->sep_cell_len);
575 *out_heap = data;
576 return clen;
577}
578
579// Write a completed interior page to disk and record it as a parent.
580// Returns updated parent_count, or -1 on allocation failure.

Callers 1

fill_interior_pageFunction · 0.85

Calls 2

put_u32Function · 0.85
put_varintFunction · 0.85

Tested by

no test coverage detected