This commit is contained in:
Hongze Cheng 2022-03-15 10:28:18 +00:00
parent f906282c6c
commit 9f9c7120bc
1 changed files with 38 additions and 48 deletions

View File

@ -48,14 +48,23 @@ typedef struct {
SBTree *pBt; SBTree *pBt;
} SBtreeZeroPageArg; } SBtreeZeroPageArg;
typedef struct {
int kLen;
u8 *pKey;
int vLen;
u8 *pVal;
SPgno pgno;
u8 *pTmpSpace;
} SCellDecoder;
static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *pCRst); static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *pCRst);
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 tdbBtreeZeroPage(SPage *pPage, void *arg);
static int tdbBtreeInitPage(SPage *pPage, void *arg); static int tdbBtreeInitPage(SPage *pPage, void *arg);
static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell, static int tdbBtreeEncodeCell(SPage *pPage, const void *pKey, int kLen, const void *pVal, int vLen, SCell *pCell,
int *szCell); int *szCell);
static int tdbBtreeDecodeCell(SPage *pPage, const SCell *pCell, SCellDecoder *pDecoder);
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;
@ -201,45 +210,40 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen, int *p
return 0; return 0;
} }
// Search from root page down to leaf for (;;) {
{ int lidx, ridx, midx, c;
// TODO SCell *pCell;
ASSERT(0); SPage *pPage;
// ret = tdbBtCursorMoveToRoot(pCur); SCellDecoder cd = {0};
// if (ret < 0) {
// return -1;
// }
// if (pCur->pPage->pHdr->nCells == 0) { pPage = pCur->pPage;
// // Tree is empty lidx = 0;
// } else { ridx = TDB_PAGE_NCELLS(pPage) - 1;
// for (;;) { midx = (lidx + ridx) >> 1;
// int lidx, ridx, midx, c; for (;;) {
pCell = TDB_PAGE_CELL_AT(pPage, midx);
ret = tdbBtreeDecodeCell(pPage, pCell, &cd);
if (ret < 0) {
// TODO: handle error
ASSERT(0);
return -1;
}
// pBtPage = pCur->pPage; // Compare the key values
// lidx = 0; c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen);
// ridx = pBtPage->pHdr->nCells - 1; if (c < 0) {
// while (lidx <= ridx) { /* TODO */
// midx = (lidx + ridx) >> 1; } else if (c > 0) {
// pCell = (void *)(pBtPage->aData + pBtPage->pCellIdx[midx]); /* TODO */
} else {
// c = tdbCompareKeyAndCell(pKey, kLen, pCell); /* TODO */
// if (c == 0) { }
// break; }
// } else if (c < 0) {
// lidx = lidx + 1;
// } else {
// ridx = ridx - 1;
// }
// }
// }
// /* code */
// }
} }
} else { } else {
// TODO: Move the cursor from a some position instead of a clear state // TODO: Move the cursor from a some position instead of a clear state
ASSERT(0);
} }
return 0; return 0;
@ -271,11 +275,6 @@ static int tdbBtCursorMoveToRoot(SBtCursor *pCur) {
return 0; return 0;
} }
static int tdbCompareKeyAndCell(const void *pKey, int kLen, const void *pCell) {
/* TODO */
return 0;
}
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) {
int mlen; int mlen;
int cret; int cret;
@ -701,15 +700,6 @@ static int tdbBtreeBalance(SBtCursor *pCur) {
#endif #endif
#ifndef TDB_BTREE_CELL // ========================================================= #ifndef TDB_BTREE_CELL // =========================================================
typedef struct {
int kLen;
u8 *pKey;
int vLen;
u8 *pVal;
SPgno pgno;
u8 *pTmpSpace;
} SCellDecoder;
static int tdbBtreeEncodePayload(SPage *pPage, u8 *pPayload, const void *pKey, int kLen, const void *pVal, int vLen, static int tdbBtreeEncodePayload(SPage *pPage, u8 *pPayload, const void *pKey, int kLen, const void *pVal, int vLen,
int *szPayload) { int *szPayload) {
int nPayload; int nPayload;