MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / write_one_table

Function write_one_table

internal/cbm/sqlite_writer.c:1860–1883  ·  view source on GitHub ↗

Write a streaming B-tree table from count items, or an empty table if count == 0. */

Source from the content-addressed store, hash-verified

1858
1859/* Write a streaming B-tree table from count items, or an empty table if count == 0. */
1860static int write_one_table(write_db_ctx_t *w, uint32_t *root, const void *items, int count,
1861 fill_record_fn fill_rec, get_rowid_fn get_id) {
1862 if (count <= 0 || !items) {
1863 *root = write_table_btree(w->fp, &w->next_page, NULL, NULL, NULL, 0, false);
1864 return 0;
1865 }
1866 PageBuilder pb;
1867 pb_init(&pb, w->fp, w->next_page, false);
1868 for (int i = 0; i < count; i++) {
1869 RecordBuilder r;
1870 rec_init(&r);
1871 fill_rec(&r, items, i);
1872 int64_t rowid = get_id(items, i);
1873 int64_t prev_id = i > 0 ? get_id(items, i - SKIP_ONE) : 0;
1874 bool placed = pb_add_table_record_with_flush(&pb, rowid, &r, prev_id);
1875 rec_free(&r);
1876 if (!placed) {
1877 pb_free(&pb);
1878 return ERR_WRITE_FAILED;
1879 }
1880 }
1881 *root = pb_finalize_table(&pb, &w->next_page, get_id(items, count - SKIP_ONE));
1882 return 0;
1883}
1884
1885/* Adapter functions for write_one_table (nodes are written via the streaming
1886 * PageBuilder in cbm_writer_append_nodes, so no node adapter is needed here). */

Callers 1

write_db_after_nodesFunction · 0.85

Calls 7

write_table_btreeFunction · 0.85
pb_initFunction · 0.85
rec_initFunction · 0.85
rec_freeFunction · 0.85
pb_freeFunction · 0.85
pb_finalize_tableFunction · 0.85

Tested by

no test coverage detected