more TDB
This commit is contained in:
parent
665eb2e20a
commit
f1619fee85
|
@ -29,23 +29,6 @@ struct SBTree {
|
||||||
int minLeaf;
|
int minLeaf;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct SPgHdr {
|
|
||||||
u8 flags;
|
|
||||||
u8 fragmentTotalSize;
|
|
||||||
u16 firstFreeCellOffset;
|
|
||||||
u16 nCells;
|
|
||||||
u16 pCell;
|
|
||||||
i32 kLen;
|
|
||||||
i32 vLen;
|
|
||||||
SPgno rightChild;
|
|
||||||
} SPgHdr;
|
|
||||||
|
|
||||||
struct SBtPage {
|
|
||||||
SPgHdr *pHdr;
|
|
||||||
u16 * aCellIdx;
|
|
||||||
u8 * aData;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef struct SFreeCell {
|
typedef struct SFreeCell {
|
||||||
u16 size;
|
u16 size;
|
||||||
u16 next;
|
u16 next;
|
||||||
|
@ -140,32 +123,32 @@ static int tdbBtCursorMoveTo(SBtCursor *pCur, const void *pKey, int kLen) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pCur->pPage->pHdr->nCells == 0) {
|
// if (pCur->pPage->pHdr->nCells == 0) {
|
||||||
// Tree is empty
|
// // Tree is empty
|
||||||
} else {
|
// } else {
|
||||||
for (;;) {
|
// for (;;) {
|
||||||
int lidx, ridx, midx, c;
|
// int lidx, ridx, midx, c;
|
||||||
|
|
||||||
pBtPage = pCur->pPage;
|
// pBtPage = pCur->pPage;
|
||||||
lidx = 0;
|
// lidx = 0;
|
||||||
ridx = pBtPage->pHdr->nCells - 1;
|
// ridx = pBtPage->pHdr->nCells - 1;
|
||||||
while (lidx <= ridx) {
|
// while (lidx <= ridx) {
|
||||||
midx = (lidx + ridx) >> 1;
|
// midx = (lidx + ridx) >> 1;
|
||||||
pCell = (void *)(pBtPage->aData + pBtPage->aCellIdx[midx]);
|
// pCell = (void *)(pBtPage->aData + pBtPage->aCellIdx[midx]);
|
||||||
|
|
||||||
c = tdbCompareKeyAndCell(pKey, kLen, pCell);
|
// c = tdbCompareKeyAndCell(pKey, kLen, pCell);
|
||||||
if (c == 0) {
|
// if (c == 0) {
|
||||||
break;
|
// break;
|
||||||
} else if (c < 0) {
|
// } else if (c < 0) {
|
||||||
lidx = lidx + 1;
|
// lidx = lidx + 1;
|
||||||
} else {
|
// } else {
|
||||||
ridx = ridx - 1;
|
// ridx = ridx - 1;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/* code */
|
// /* code */
|
||||||
}
|
// }
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -254,10 +237,10 @@ static int tdbBtCursorMoveToRoot(SBtCursor *pCur) {
|
||||||
static int tdbInitBtPage(SPage *pPage, SBtPage **ppBtPage) {
|
static int tdbInitBtPage(SPage *pPage, SBtPage **ppBtPage) {
|
||||||
SBtPage *pBtPage;
|
SBtPage *pBtPage;
|
||||||
|
|
||||||
pBtPage = (SBtPage *)pPage->pExtra;
|
// pBtPage = (SBtPage *)pPage->pExtra;
|
||||||
pBtPage->pHdr = (SPgHdr *)pPage->pData;
|
// pBtPage->pHdr = (SPgHdr *)pPage->pData;
|
||||||
pBtPage->aCellIdx = (u16 *)(&((pBtPage->pHdr)[1]));
|
// pBtPage->aCellIdx = (u16 *)(&((pBtPage->pHdr)[1]));
|
||||||
pBtPage->aData = (u8 *)pPage->pData;
|
// pBtPage->aData = (u8 *)pPage->pData;
|
||||||
|
|
||||||
*ppBtPage = pBtPage;
|
*ppBtPage = pBtPage;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue