Build interior pages from child page references. Returns the root page number. SQLite interior page structure: - Header has right-child pointer (the last child page) - Each cell contains: child_page(4) + key - For N children, there are N-1 cells (children[0..N-2] get cells, children[N-1] becomes the right-child in the header) - Cell[j] = {left_child: children[j].page, key: children[j].max_key/sep
| 562 | // cell_buf must be at least 20 bytes for table cells. |
| 563 | // For index cells, returns malloc'd data via *out_heap (caller frees). |
| 564 | static int build_interior_cell(const PageRef *child, bool is_index, uint8_t *cell_buf, |
| 565 | uint8_t **out_heap) { |
| 566 | *out_heap = NULL; |
| 567 | if (!is_index) { |
| 568 | put_u32(cell_buf, child->page_num); |
| 569 | return BTREE_PTR_SIZE + put_varint(cell_buf + BTREE_PTR_SIZE, child->max_key); |
| 570 | } |
| 571 | int clen = BTREE_PTR_SIZE + child->sep_cell_len; |
| 572 | uint8_t *data = (uint8_t *)malloc(clen); |
| 573 | put_u32(data, child->page_num); |
| 574 | memcpy(data + 4, child->sep_cell, child->sep_cell_len); |
| 575 | *out_heap = data; |
| 576 | return clen; |
| 577 | } |
| 578 | |
| 579 | // Write a completed interior page to disk and record it as a parent. |
| 580 | // Returns updated parent_count, or -1 on allocation failure. |
no test coverage detected