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:1222–1240  ·  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

1220
1221// Promote the last cell from current page to separator, un-add it, and flush.
1222static bool pb_promote_and_flush(PageBuilder *pb, uint8_t **cells, int *cell_lens, int prev_idx) {
1223 if (!pb_ensure_leaf_cap(pb)) {
1224 return false;
1225 }
1226 pb->leaves[pb->leaf_count].max_key = 0;
1227 pb->leaves[pb->leaf_count].sep_cell = (uint8_t *)malloc(cell_lens[prev_idx]);
1228 memcpy(pb->leaves[pb->leaf_count].sep_cell, cells[prev_idx], cell_lens[prev_idx]);
1229 pb->leaves[pb->leaf_count].sep_cell_len = cell_lens[prev_idx];
1230
1231 // Un-add the last cell — it's promoted to the interior separator.
1232 // SQLite index B-tree interior cells are counted by integrity_check,
1233 // so this cell exists in the interior page instead of the leaf.
1234 pb->cell_count--;
1235 pb->content_offset += cell_lens[prev_idx];
1236 pb->ptr_offset -= CELL_PTR_SIZE;
1237
1238 pb_flush_leaf(pb);
1239 return true;
1240}
1241
1242// Write an empty index leaf page.
1243static 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