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

Function pb_promote_and_flush

internal/cbm/sqlite_writer.c:1243–1261  ·  view source on GitHub ↗

Promote the last cell from current page to separator, un-add it, and flush.

Source from the content-addressed store, hash-verified

1241
1242// Promote the last cell from current page to separator, un-add it, and flush.
1243static bool pb_promote_and_flush(PageBuilder *pb, uint8_t **cells, int *cell_lens, int prev_idx) {
1244 if (!pb_ensure_leaf_cap(pb)) {
1245 return false;
1246 }
1247 pb->leaves[pb->leaf_count].max_key = 0;
1248 pb->leaves[pb->leaf_count].sep_cell = (uint8_t *)malloc(cell_lens[prev_idx]);
1249 memcpy(pb->leaves[pb->leaf_count].sep_cell, cells[prev_idx], cell_lens[prev_idx]);
1250 pb->leaves[pb->leaf_count].sep_cell_len = cell_lens[prev_idx];
1251
1252 // Un-add the last cell — it's promoted to the interior separator.
1253 // SQLite index B-tree interior cells are counted by integrity_check,
1254 // so this cell exists in the interior page instead of the leaf.
1255 pb->cell_count--;
1256 pb->content_offset += cell_lens[prev_idx];
1257 pb->ptr_offset -= CELL_PTR_SIZE;
1258
1259 pb_flush_leaf(pb);
1260 return true;
1261}
1262
1263// Write an empty index leaf page.
1264static uint32_t write_empty_index_leaf(FILE *fp, uint32_t *next_page) {

Callers 1

write_index_btreeFunction · 0.85

Calls 2

pb_ensure_leaf_capFunction · 0.85
pb_flush_leafFunction · 0.85

Tested by

no test coverage detected