Finalize a table PageBuilder: flush last leaf and build interior pages.
| 1233 | |
| 1234 | // Finalize a table PageBuilder: flush last leaf and build interior pages. |
| 1235 | static uint32_t pb_finalize_table(PageBuilder *pb, uint32_t *next_page, int64_t last_rowid) { |
| 1236 | if (pb->cell_count > 0) { |
| 1237 | pb_ensure_leaf_cap(pb); |
| 1238 | if (!pb->leaves) { |
| 1239 | pb_free(pb); |
| 1240 | return 0; |
| 1241 | } |
| 1242 | pb->leaves[pb->leaf_count].max_key = last_rowid; |
| 1243 | pb->leaves[pb->leaf_count].sep_cell = NULL; |
| 1244 | pb->leaves[pb->leaf_count].sep_cell_len = 0; |
| 1245 | pb_flush_leaf(pb); |
| 1246 | } |
| 1247 | |
| 1248 | *next_page = pb->next_page; |
| 1249 | uint32_t root; |
| 1250 | if (pb->leaf_count == SKIP_ONE) { |
| 1251 | root = pb->leaves[0].page_num; |
| 1252 | } else if (pb->leaf_count > SKIP_ONE) { |
| 1253 | root = pb_build_interior(pb, false); |
| 1254 | *next_page = pb->next_page; |
| 1255 | } else { |
| 1256 | root = 0; // shouldn't happen when count > 0 |
| 1257 | } |
| 1258 | pb_free(pb); |
| 1259 | return root; |
| 1260 | } |
| 1261 | |
| 1262 | // Write leaf pages for a table, returns root page. |
| 1263 | // rowids must be sequential starting from 1 (or single-row PK text). |
no test coverage detected