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

Function pb_finalize_table

internal/cbm/sqlite_writer.c:1180–1205  ·  view source on GitHub ↗

Finalize a table PageBuilder: flush last leaf and build interior pages.

Source from the content-addressed store, hash-verified

1178
1179// Finalize a table PageBuilder: flush last leaf and build interior pages.
1180static uint32_t pb_finalize_table(PageBuilder *pb, uint32_t *next_page, int64_t last_rowid) {
1181 if (pb->cell_count > 0) {
1182 pb_ensure_leaf_cap(pb);
1183 if (!pb->leaves) {
1184 pb_free(pb);
1185 return 0;
1186 }
1187 pb->leaves[pb->leaf_count].max_key = last_rowid;
1188 pb->leaves[pb->leaf_count].sep_cell = NULL;
1189 pb->leaves[pb->leaf_count].sep_cell_len = 0;
1190 pb_flush_leaf(pb);
1191 }
1192
1193 *next_page = pb->next_page;
1194 uint32_t root;
1195 if (pb->leaf_count == SKIP_ONE) {
1196 root = pb->leaves[0].page_num;
1197 } else if (pb->leaf_count > SKIP_ONE) {
1198 root = pb_build_interior(pb, false);
1199 *next_page = pb->next_page;
1200 } else {
1201 root = 0; // shouldn't happen when count > 0
1202 }
1203 pb_free(pb);
1204 return root;
1205}
1206
1207// Write leaf pages for a table, returns root page.
1208// rowids must be sequential starting from 1 (or single-row PK text).

Callers 3

write_table_btreeFunction · 0.85
write_one_tableFunction · 0.85
cbm_writer_finalizeFunction · 0.85

Calls 4

pb_ensure_leaf_capFunction · 0.85
pb_freeFunction · 0.85
pb_flush_leafFunction · 0.85
pb_build_interiorFunction · 0.85

Tested by

no test coverage detected