This commit is contained in:
Hongze Cheng 2022-03-04 02:10:06 +00:00
parent f4a863e52e
commit 90789973de
1 changed files with 37 additions and 29 deletions

View File

@ -40,12 +40,19 @@ typedef struct SFreeCell {
u16 next; u16 next;
} SFreeCell; } SFreeCell;
typedef struct {
u16 flags;
SBTree *pBt;
} SBtreeZeroPageArg;
static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen); static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen);
static int tdbEncodeLength(u8 *pBuf, uint32_t len); static int tdbEncodeLength(u8 *pBuf, uint32_t len);
static int tdbBtCursorMoveToRoot(SBtCursor *pCur); static int tdbBtCursorMoveToRoot(SBtCursor *pCur);
static int tdbCompareKeyAndCell(const void *pKey, int kLen, const void *pCell); static int tdbCompareKeyAndCell(const void *pKey, int kLen, const void *pCell);
static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2); static int tdbDefaultKeyCmprFn(const void *pKey1, int keyLen1, const void *pKey2, int keyLen2);
static int tdbBtreeOpenImpl(SBTree *pBt); static int tdbBtreeOpenImpl(SBTree *pBt);
static int tdbBtreeZeroPage(SPage *pPage, void *arg);
static int tdbBtreeInitPage(SPage *pPage, void *arg);
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;
@ -296,45 +303,46 @@ static int tdbBtreeOpenImpl(SBTree *pBt) {
} }
static int tdbBtreeZeroPage(SPage *pPage, void *arg) { static int tdbBtreeZeroPage(SPage *pPage, void *arg) {
u16 flags;
SBTree *pBt;
flags = ((SBtreeZeroPageArg *)arg)->flags;
pBt = ((SBtreeZeroPageArg *)arg)->pBt;
pPage->pPageHdr = (SPageHdr *)pPage->pData; pPage->pPageHdr = (SPageHdr *)pPage->pData;
pPage->aCellIdx = (u16 *)(&(pPage->pPageHdr[1])); pPage->aCellIdx = (u16 *)(&(pPage->pPageHdr[1]));
// Init the page header // Init the page header
{ pPage->pPageHdr->flags = flags;
#if 0
pPage->pPageHdr->flags = 0;
pPage->pPageHdr->nCells = 0; pPage->pPageHdr->nCells = 0;
pPage->pPageHdr->cellCont = 0; pPage->pPageHdr->cellCont = 0;
pPage->pPageHdr->freeCell = 0; pPage->pPageHdr->freeCell = 0;
pPage->pPageHdr->nFree = 0; pPage->pPageHdr->nFree = 0;
#endif
}
// Init other fields tdbBtreeInitPage(pPage, (void *)pBt);
{
#if 0
pPage->kLen = pBt->keyLen;
pPage->vLen = pBt->valLen;
pPage->maxLocal = pBt->maxLocal;
pPage->minLocal = pBt->minLocal;
#endif
}
return 0; return 0;
} }
static int tdbBtreeInitPage(SPage *pPage, void *arg) { static int tdbBtreeInitPage(SPage *pPage, void *arg) {
SBTree *pBt;
pBt = (SBTree *)arg;
pPage->pPageHdr = (SPageHdr *)pPage->pData; pPage->pPageHdr = (SPageHdr *)pPage->pData;
pPage->aCellIdx = (u16 *)(&(pPage->pPageHdr[1])); pPage->aCellIdx = (u16 *)(&(pPage->pPageHdr[1]));
// Init other fields // Init other fields
{ if (TDB_BTREE_PAGE_IS_LEAF(pPage->pPageHdr->flags)) {
#if 0
pPage->kLen = pBt->keyLen; pPage->kLen = pBt->keyLen;
pPage->vLen = pBt->valLen; pPage->vLen = pBt->valLen;
pPage->maxLocal = pBt->maxLeaf;
pPage->minLocal = pBt->minLeaf;
} else {
pPage->kLen = pBt->keyLen;
pPage->vLen = sizeof(SPgno);
pPage->maxLocal = pBt->maxLocal; pPage->maxLocal = pBt->maxLocal;
pPage->minLocal = pBt->minLocal; pPage->minLocal = pBt->minLocal;
#endif
} }
return 0; return 0;