more TDB
This commit is contained in:
parent
f906282c6c
commit
9f9c7120bc
|
@ -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;
|
||||||
|
SPage *pPage;
|
||||||
|
SCellDecoder cd = {0};
|
||||||
|
|
||||||
|
pPage = pCur->pPage;
|
||||||
|
lidx = 0;
|
||||||
|
ridx = TDB_PAGE_NCELLS(pPage) - 1;
|
||||||
|
midx = (lidx + ridx) >> 1;
|
||||||
|
for (;;) {
|
||||||
|
pCell = TDB_PAGE_CELL_AT(pPage, midx);
|
||||||
|
ret = tdbBtreeDecodeCell(pPage, pCell, &cd);
|
||||||
|
if (ret < 0) {
|
||||||
|
// TODO: handle error
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
// ret = tdbBtCursorMoveToRoot(pCur);
|
return -1;
|
||||||
// if (ret < 0) {
|
}
|
||||||
// return -1;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if (pCur->pPage->pHdr->nCells == 0) {
|
// Compare the key values
|
||||||
// // Tree is empty
|
c = pBt->kcmpr(pKey, kLen, cd.pKey, cd.kLen);
|
||||||
// } else {
|
if (c < 0) {
|
||||||
// for (;;) {
|
/* TODO */
|
||||||
// int lidx, ridx, midx, c;
|
} else if (c > 0) {
|
||||||
|
/* TODO */
|
||||||
// pBtPage = pCur->pPage;
|
} else {
|
||||||
// lidx = 0;
|
/* TODO */
|
||||||
// ridx = pBtPage->pHdr->nCells - 1;
|
}
|
||||||
// while (lidx <= ridx) {
|
}
|
||||||
// midx = (lidx + ridx) >> 1;
|
|
||||||
// pCell = (void *)(pBtPage->aData + pBtPage->pCellIdx[midx]);
|
|
||||||
|
|
||||||
// c = tdbCompareKeyAndCell(pKey, kLen, pCell);
|
|
||||||
// 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;
|
||||||
|
|
Loading…
Reference in New Issue