diff --git a/source/libs/tdb/src/db/tdbPage.c b/source/libs/tdb/src/db/tdbPage.c index e0024f7472ef5fcfda7a6c64eb29fb26a2d954ca..cd76ff33549e88dd82f47fc83f448265c43e96b6 100644 --- a/source/libs/tdb/src/db/tdbPage.c +++ b/source/libs/tdb/src/db/tdbPage.c @@ -51,7 +51,18 @@ int tdbPageDestroy(SPage *pPage, void (*xFree)(void *arg, void *ptr), void *arg) } int tdbPageInsertCell(SPage *pPage, int idx, SCell *pCell, int szCell) { - // TODO + int ret; + SCell *pTarget; + + if (pPage->nOverflow || szCell + TDB_PAGE_CELL_OFFSET_SIZE(pPage) > pPage->nFree) { + // TODO + } else { + ret = tdbPageAllocate(pPage, szCell, &pTarget); + if (ret < 0) { + return -1; + } + } + return 0; } @@ -61,11 +72,29 @@ int tdbPageDropCell(SPage *pPage, int idx) { } static int tdbPageAllocate(SPage *pPage, int size, SCell **ppCell) { - // TODO + SCell *pCell; + int szOffset; + + szOffset = TDB_PAGE_CELL_OFFSET_SIZE(pPage); + ASSERT(pPage->nFree > size + szOffset); + + if (pPage->pFreeEnd - pPage->pFreeStart > size + szOffset) { + pPage->pFreeEnd -= size; + pPage->pFreeStart += szOffset; + + pCell = pPage->pFreeEnd; + } else { + } + return 0; } static int tdbPageFree(SPage *pPage, int idx, SCell *pCell, int size) { // TODO return 0; +} + +static int tdbPageDefragment(SPage *pPage) { + // TODO + return 0; } \ No newline at end of file diff --git a/source/libs/tdb/src/inc/tdbPage.h b/source/libs/tdb/src/inc/tdbPage.h index ee35d0df1dfb94f1bb80969fece9dd255c25b2fa..25137e8dc3ae9cd946b6d007d4c871a4e8de8d98 100644 --- a/source/libs/tdb/src/inc/tdbPage.h +++ b/source/libs/tdb/src/inc/tdbPage.h @@ -44,8 +44,11 @@ struct SPage { SPageHdr *pPageHdr; SPageFtr *pPageFtr; u16 *aCellIdx; + u8 *pFreeStart; + u8 *pFreeEnd; int kLen; int vLen; + int nFree; int maxLocal; int minLocal; int nOverflow;