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
| 580 | // cell_buf must be at least 20 bytes for table cells. |
| 581 | // For index cells, returns malloc'd data via *out_heap (caller frees). |
| 582 | static int build_interior_cell(const PageRef *child, bool is_index, uint8_t *cell_buf, |
| 583 | uint8_t **out_heap) { |
| 584 | *out_heap = NULL; |
| 585 | if (!is_index) { |
| 586 | put_u32(cell_buf, child->page_num); |
| 587 | return BTREE_PTR_SIZE + put_varint(cell_buf + BTREE_PTR_SIZE, child->max_key); |
| 588 | } |
| 589 | int clen = BTREE_PTR_SIZE + child->sep_cell_len; |
| 590 | uint8_t *data = (uint8_t *)malloc(clen); |
| 591 | put_u32(data, child->page_num); |
| 592 | memcpy(data + 4, child->sep_cell, child->sep_cell_len); |
| 593 | *out_heap = data; |
| 594 | return clen; |
| 595 | } |
| 596 | |
| 597 | // Write a completed interior page to disk and record it as a parent. |
| 598 | // Returns updated parent_count, or -1 on allocation failure. |
no test coverage detected