more
This commit is contained in:
parent
7c7c0fb5f6
commit
7cd83134d2
|
@ -35,11 +35,13 @@ typedef struct SPgHdr {
|
||||||
u16 pCell;
|
u16 pCell;
|
||||||
i32 kLen;
|
i32 kLen;
|
||||||
i32 vLen;
|
i32 vLen;
|
||||||
|
SPgno rightChild;
|
||||||
} SPgHdr;
|
} SPgHdr;
|
||||||
|
|
||||||
typedef struct SBtPage {
|
typedef struct SBtPage {
|
||||||
SPgHdr *pHdr;
|
SPgHdr *pHdr;
|
||||||
u16 * aCellIdx;
|
u16 * aCellIdx;
|
||||||
|
u8 * aData;
|
||||||
} SBtPage;
|
} SBtPage;
|
||||||
|
|
||||||
struct SBtCursor {
|
struct SBtCursor {
|
||||||
|
@ -48,10 +50,16 @@ struct SBtCursor {
|
||||||
SBtPage *pPage;
|
SBtPage *pPage;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef struct SFreeCell {
|
||||||
|
u16 size;
|
||||||
|
u16 next;
|
||||||
|
} SFreeCell;
|
||||||
|
|
||||||
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, uint len);
|
static int tdbEncodeLength(u8 *pBuf, uint len);
|
||||||
static int tdbBtCursorMoveToRoot(SBtCursor *pCur);
|
static int tdbBtCursorMoveToRoot(SBtCursor *pCur);
|
||||||
static int tdbInitBtPage(SPage *pPage, SBtPage **ppBtPage);
|
static int tdbInitBtPage(SPage *pPage, SBtPage **ppBtPage);
|
||||||
|
static int tdbCompareKeyAndCell(const void *pKey, int kLen, const void *pCell);
|
||||||
|
|
||||||
int tdbBtreeOpen(SPgno root, SBTree **ppBt) {
|
int tdbBtreeOpen(SPgno root, SBTree **ppBt) {
|
||||||
*ppBt = NULL;
|
*ppBt = NULL;
|
||||||
|
@ -93,9 +101,37 @@ int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *p
|
||||||
|
|
||||||
static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen) {
|
static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen) {
|
||||||
int ret;
|
int ret;
|
||||||
|
SBtPage *pBtPage;
|
||||||
|
void * pCell;
|
||||||
|
|
||||||
ret = tdbBtCursorMoveToRoot(pCur);
|
ret = tdbBtCursorMoveToRoot(pCur);
|
||||||
// TODO
|
if (ret < 0) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (;;) {
|
||||||
|
int lidx, ridx, midx, c;
|
||||||
|
|
||||||
|
pBtPage = pCur->pPage;
|
||||||
|
lidx = 0;
|
||||||
|
ridx = pBtPage->pHdr->nCells - 1;
|
||||||
|
while (lidx <= ridx) {
|
||||||
|
midx = (lidx + ridx) >> 1;
|
||||||
|
pCell = (void *)(pBtPage->aData + pBtPage->aCellIdx[midx]);
|
||||||
|
|
||||||
|
c = tdbCompareKeyAndCell(pKey, kLen, pCell);
|
||||||
|
if (c == 0) {
|
||||||
|
break;
|
||||||
|
} else if (c < 0) {
|
||||||
|
lidx = lidx + 1;
|
||||||
|
} else {
|
||||||
|
ridx = ridx - 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* code */
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -181,6 +217,17 @@ static int tdbBtCursorMoveToRoot(SBtCursor *pCur) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tdbInitBtPage(SPage *pPage, SBtPage **ppBtPage) {
|
static int tdbInitBtPage(SPage *pPage, SBtPage **ppBtPage) {
|
||||||
// TODO
|
SBtPage *pBtPage;
|
||||||
|
|
||||||
|
pBtPage = (SBtPage *)pPage->pExtra;
|
||||||
|
pBtPage->pHdr = (SPgHdr *)pPage->pData;
|
||||||
|
pBtPage->aCellIdx = (u16 *)(&((pBtPage->pHdr)[1]));
|
||||||
|
pBtPage->aData = (u8 *)pPage->pData;
|
||||||
|
|
||||||
|
*ppBtPage = pBtPage;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
static int tdbCompareKeyAndCell(const void *pKey, int kLen, const void *pCell) {
|
||||||
|
/* TODO */
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
Loading…
Reference in New Issue