more TDB
This commit is contained in:
parent
f4a863e52e
commit
90789973de
|
@ -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;
|
||||||
|
@ -110,8 +117,8 @@ int tdbBtreeCursor(SBtCursor *pCur, SBTree *pBt) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *pVal, int vLen) {
|
int tdbBtCursorInsert(SBtCursor *pCur, const void *pKey, int kLen, const void *pVal, int vLen) {
|
||||||
int ret;
|
int ret;
|
||||||
SPager * pPager;
|
SPager *pPager;
|
||||||
|
|
||||||
ret = tdbBtCursorMoveTo(pCur, pKey, kLen);
|
ret = tdbBtCursorMoveTo(pCur, pKey, kLen);
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
|
@ -123,8 +130,8 @@ 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;
|
||||||
void * pCell;
|
void *pCell;
|
||||||
|
|
||||||
// ret = tdbBtCursorMoveToRoot(pCur);
|
// ret = tdbBtCursorMoveToRoot(pCur);
|
||||||
// if (ret < 0) {
|
// if (ret < 0) {
|
||||||
|
@ -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->nCells = 0;
|
||||||
pPage->pPageHdr->flags = 0;
|
pPage->pPageHdr->cellCont = 0;
|
||||||
pPage->pPageHdr->nCells = 0;
|
pPage->pPageHdr->freeCell = 0;
|
||||||
pPage->pPageHdr->cellCont = 0;
|
pPage->pPageHdr->nFree = 0;
|
||||||
pPage->pPageHdr->freeCell = 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->maxLocal = pBt->maxLocal;
|
pPage->minLocal = pBt->minLeaf;
|
||||||
pPage->minLocal = pBt->minLocal;
|
} else {
|
||||||
#endif
|
pPage->kLen = pBt->keyLen;
|
||||||
|
pPage->vLen = sizeof(SPgno);
|
||||||
|
pPage->maxLocal = pBt->maxLocal;
|
||||||
|
pPage->minLocal = pBt->minLocal;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Reference in New Issue