Write a streaming B-tree table from count items, or an empty table if count == 0. */
| 1802 | |
| 1803 | /* Write a streaming B-tree table from count items, or an empty table if count == 0. */ |
| 1804 | static int write_one_table(write_db_ctx_t *w, uint32_t *root, const void *items, int count, |
| 1805 | build_record_fn build_rec, get_rowid_fn get_id) { |
| 1806 | if (count <= 0 || !items) { |
| 1807 | *root = write_table_btree(w->fp, &w->next_page, NULL, NULL, NULL, 0, false); |
| 1808 | return 0; |
| 1809 | } |
| 1810 | PageBuilder pb; |
| 1811 | pb_init(&pb, w->fp, w->next_page, false); |
| 1812 | for (int i = 0; i < count; i++) { |
| 1813 | int rec_len; |
| 1814 | uint8_t *rec = build_rec(items, i, &rec_len); |
| 1815 | if (!rec) { |
| 1816 | return ERR_WRITE_FAILED; |
| 1817 | } |
| 1818 | int64_t rowid = get_id(items, i); |
| 1819 | int64_t prev_id = i > 0 ? get_id(items, i - SKIP_ONE) : 0; |
| 1820 | pb_add_table_cell_with_flush(&pb, rowid, rec, rec_len, prev_id); |
| 1821 | free(rec); |
| 1822 | } |
| 1823 | *root = pb_finalize_table(&pb, &w->next_page, get_id(items, count - SKIP_ONE)); |
| 1824 | return 0; |
| 1825 | } |
| 1826 | |
| 1827 | /* Adapter functions for write_one_table (nodes are written via the streaming |
| 1828 | * PageBuilder in cbm_writer_append_nodes, so no node adapter is needed here). */ |
no test coverage detected