This commit is contained in:
Hongze Cheng 2022-03-21 06:23:32 +00:00
parent d9c4bcab6c
commit a84155b951
3 changed files with 17 additions and 10 deletions

View File

@ -52,9 +52,9 @@ typedef struct __attribute__((__packed__)) {
} SIntHdr; } SIntHdr;
typedef struct { typedef struct {
u16 flags; u8 flags;
SBTree *pBt; SBTree *pBt;
} SBtreeZeroPageArg; } SBtreeInitPageArg;
typedef struct { typedef struct {
int kLen; int kLen;
@ -74,6 +74,7 @@ static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const vo
int *szCell); int *szCell);
static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder); static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder);
static int tdbBtreeBalance(SBtCursor *pCur); static int tdbBtreeBalance(SBtCursor *pCur);
static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell);
int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) { int tdbBtreeOpen(int keyLen, int valLen, SPager *pPager, FKeyComparator kcmpr, SBTree **ppBt) {
SBTree *pBt; SBTree *pBt;
@ -371,7 +372,7 @@ static int tdbBtreeOpenImpl(SBTree *pBt) {
} }
// Try to create a new database // Try to create a new database
SBtreeZeroPageArg zArg = {.flags = TDB_BTREE_ROOT | TDB_BTREE_LEAF, .pBt = pBt}; SBtreeInitPageArg zArg = {.flags = TDB_BTREE_ROOT | TDB_BTREE_LEAF, .pBt = pBt};
ret = tdbPagerNewPage(pBt->pPager, &pgno, &pPage, tdbBtreeZeroPage, &zArg); ret = tdbPagerNewPage(pBt->pPager, &pgno, &pPage, tdbBtreeZeroPage, &zArg);
if (ret < 0) { if (ret < 0) {
return -1; return -1;
@ -430,8 +431,8 @@ static int tdbBtreeZeroPage(SPage *pPage, void *arg) {
u8 isLeaf; u8 isLeaf;
u8 szAmHdr; u8 szAmHdr;
flags = ((SBtreeZeroPageArg *)arg)->flags; flags = ((SBtreeInitPageArg *)arg)->flags;
pBt = ((SBtreeZeroPageArg *)arg)->pBt; pBt = ((SBtreeInitPageArg *)arg)->pBt;
isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags); isLeaf = TDB_BTREE_PAGE_IS_LEAF(flags);
if (isLeaf) { if (isLeaf) {
@ -498,7 +499,7 @@ static int tdbBtreeBalanceDeeper(SBTree *pBt, SPage *pRoot, SPage **ppChild) {
SPage *pChild; SPage *pChild;
SPgno pgnoChild; SPgno pgnoChild;
int ret; int ret;
SBtreeZeroPageArg zArg; SBtreeInitPageArg zArg;
pPager = pRoot->pPager; pPager = pRoot->pPager;
@ -960,3 +961,9 @@ static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pD
} }
#endif #endif
static int tdbBtreeCellSize(const SPage *pPage, SCell *pCell) {
// TODO
ASSERT(0);
return 0;
}

View File

@ -71,7 +71,7 @@ struct SPage {
int vLen; // value length of the page, -1 for unknown int vLen; // value length of the page, -1 for unknown
int maxLocal; int maxLocal;
int minLocal; int minLocal;
int (*xCellSize)(SCell *pCell); int (*xCellSize)(const SPage *, SCell *);
// Fields used by SPCache // Fields used by SPCache
TDB_PCACHE_PAGE TDB_PCACHE_PAGE
}; };

View File

@ -193,7 +193,7 @@ int tdbPageDropCell(SPage *pPage, int idx) {
lidx = idx - iOvfl; lidx = idx - iOvfl;
pCell = TDB_PAGE_CELL_AT(pPage, lidx); pCell = TDB_PAGE_CELL_AT(pPage, lidx);
szCell = (*pPage->xCellSize)(pCell); szCell = (*pPage->xCellSize)(pPage, pCell);
tdbPageFree(pPage, lidx, pCell, szCell); tdbPageFree(pPage, lidx, pCell, szCell);
TDB_PAGE_NCELLS_SET(pPage, nCells - 1); TDB_PAGE_NCELLS_SET(pPage, nCells - 1);
@ -366,7 +366,7 @@ static int tdbPageDefragment(SPage *pPage) {
ASSERT(pCell != NULL); ASSERT(pCell != NULL);
szCell = (*pPage->xCellSize)(pCell); szCell = (*pPage->xCellSize)(pPage, pCell);
ASSERT(pCell + szCell <= pNextCell); ASSERT(pCell + szCell <= pNextCell);
if (pCell + szCell < pNextCell) { if (pCell + szCell < pNextCell) {