Finalize a table PageBuilder: flush last leaf and build interior pages.
| 1157 | |
| 1158 | // Finalize a table PageBuilder: flush last leaf and build interior pages. |
| 1159 | static uint32_t pb_finalize_table(PageBuilder *pb, uint32_t *next_page, int64_t last_rowid) { |
| 1160 | if (pb->cell_count > 0) { |
| 1161 | pb_ensure_leaf_cap(pb); |
| 1162 | if (!pb->leaves) { |
| 1163 | pb_free(pb); |
| 1164 | return 0; |
| 1165 | } |
| 1166 | pb->leaves[pb->leaf_count].max_key = last_rowid; |
| 1167 | pb->leaves[pb->leaf_count].sep_cell = NULL; |
| 1168 | pb->leaves[pb->leaf_count].sep_cell_len = 0; |
| 1169 | pb_flush_leaf(pb); |
| 1170 | } |
| 1171 | |
| 1172 | *next_page = pb->next_page; |
| 1173 | uint32_t root; |
| 1174 | if (pb->leaf_count == SKIP_ONE) { |
| 1175 | root = pb->leaves[0].page_num; |
| 1176 | } else if (pb->leaf_count > SKIP_ONE) { |
| 1177 | root = pb_build_interior(pb, false); |
| 1178 | *next_page = pb->next_page; |
| 1179 | } else { |
| 1180 | root = 0; // shouldn't happen when count > 0 |
| 1181 | } |
| 1182 | pb_free(pb); |
| 1183 | return root; |
| 1184 | } |
| 1185 | |
| 1186 | // Write leaf pages for a table, returns root page. |
| 1187 | // rowids must be sequential starting from 1 (or single-row PK text). |
no test coverage detected